开发者

How can I add a line break for the text of a UIButton? [duplicate]

开发者 https://www.devze.com 2022-12-08 11:42 出处:网络
This question already has answers here: How do you add multi-line text to a UIButton? 开发者_C百科
This question already has answers here: How do you add multi-line text to a UIButton? 开发者_C百科 (33 answers) Closed 7 years ago.

I want to know how to have a multi-line label on a UIButton.


Use the UIButton's titleLabel, specifically titleLabel.numberOfLines property:

titleLabel
A view that displays the value of the currentTitle property for a button. (read-only)

@property(nonatomic,readonly,retain) UILabel *titleLabel
Discussion
Although this property is read-only, its own properties are read/write. Use these 
properties to configure the appearance of the button label. For example:

UIButton *button                  = [UIButton buttonWithType: UIButtonTypeRoundedRect];
button.titleLabel.font            = [UIFont systemFontOfSize: 12];
button.titleLabel.lineBreakMode   = UILineBreakModeTailTruncation;
button.titleLabel.shadowOffset    = CGSizeMake (1.0, 0.0);
The titleLabel property returns a value even if the button has not been displayed yet.
The value of the property is nil for system buttons.
0

精彩评论

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