如何在iOS中处理Storyboard ViewControllers?

时间:2016-10-14 04:36:31

标签: ios objective-c iphone swift

我在ViewController中添加了3个视图,如果第二个/中间视图没有文本或者有一个行文本,则中间视图的高度应为30,最后一个视图应该在运行时向上移动。

enter image description here

2 个答案:

答案 0 :(得分:1)

ADD THIS TO YOUR CODE:

CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];   
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;

答案 1 :(得分:-1)

添加此代码

[yourlabel sizeToFit]; 要么 [yourView sizeToFit];