CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;
CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;
根据标签的高度设置按钮的边框
而不是硬编码,请使用自动版式。
Set Accept button left edge constraint to label left edge constraint.
Set Decline button right edge constraint to label right edge constraint.
Add vertical space between buttons and label.
Take label height constraint reference and set it's constant at runtime which is equal to label height.
与:一起使用
用于接受按钮:
btnAccept!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)
对于下降按钮:
btnDecline!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)
变量btnAccept是接受按钮
变量btnDecline是拒绝按钮
变量txtView是textview