开发者

Anchor UIButton to the left of a UILabel

开发者 https://www.devze.com 2022-12-22 18:57 出处:网络
I have a UILabel with right-aligned text that may vary from between three to seven characters in length. I am trying to anchor a button to the left of this text so that when the length of the text 开发

I have a UILabel with right-aligned text that may vary from between three to seven characters in length. I am trying to anchor a button to the left of this text so that when the length of the text 开发者_如何学Goincreases, the button will stay the same distance from the left of the label.

Is there an anchor setting in Interface Builder, or does it require a code-level solution (e.g. setting the button's x position according to the width of the label)?


You need to do this in code. Interface builder is not build for runtime calculations.

To calculate the width of your text you can use NSString's sizeWithFont: method.

0

精彩评论

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