Reputation: 81
How can I position a UIButton right at the end of a dynamic UILabel?
Here is a screenshot of what I'm trying to achieve:
Upvotes: 3
Views: 209
Reputation: 8490
Are you using Autolayout? If so, add horizontal spacing constraint and baseline alignment constraint between the label and the button. Make sure also that numbers of lines of the label is 0.
Upvotes: 1
Reputation: 1333
If you want the button to appear at the bottom of the UILabel, use constrains.
Upvotes: 0
Reputation: 11880
I'd override -[UIView layoutSubviews]
and do what you want there. Once you do that, the code will look something like Avt's answer. If you want the label to have multiple lines, but a constrained width, you may want to try something like
CGSize labelSize = [yourLabel sizeThatFits:CGSizeMake(someWidth, 9999)];
and use that to set the label's frame.
Upvotes: 0
Reputation: 17043
Try
[your_label sizeToFit];
CGRect rect = your_button.frame;
rect.origin.x = CGRectGetMaxX(your_label.frame);
your_button.frame = rect;
Upvotes: 0