Reputation: 311
I have taken a label and two button below the label.
I want to shift buttons upward and downward dynamically according to text in label.
Upvotes: 1
Views: 818
Reputation: 2512
Use with :
For Accept Button:
btnAccept!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)
For Decline Button:
btnDecline!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)
variable btnAccept is accept button
variable btnDecline is decline button
variable txtView is textview
Upvotes: 0
Reputation: 658
Instead of hardcoding, use Autolayout.
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.
Upvotes: 0
Reputation: 4170
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;
According to label's height set your button's frame
Upvotes: 1