开发者

IOS How to add a view next to another view?

I have a si开发者_开发问答tuation like this I want to add a UILabel next to an UILabel dynamically. But the position of the 2nd label depends on the length of the string of the 1st label which is not fixed. How to do this?


Once you set the new text to the first label, access frame property of your label.
The position for the second label would be :

CGRect f = firstLabel.frame;
CGRect f2 = CGRectMake(f.origin.x + f.size.width,
                       f.origin.y,
                       theWidthYouWant,
                       f.size.height);
secondLabel.frame = f2;

The second label is now next to the first.

If you want to add a new label to the container view, use initWithFrame: initializer with the computed frame above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜