【问题标题】:How can I add a line break for the text of a UIButton? [duplicate]如何为 UIButton 的文本添加换行符? [复制]
【发布时间】:2009-10-12 06:15:41
【问题描述】:

我想知道如何在 UIButton 上添加多行标签。

【问题讨论】:

    标签: iphone cocoa-touch uikit uibutton


    【解决方案1】:

    使用 UIButton 的 titleLabel,特别是 titleLabel.numberOfLines 属性:

    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.
    

    【讨论】:

      猜你喜欢
      • 2010-10-10
      • 2018-04-19
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2018-10-07
      • 1970-01-01
      • 2021-06-15
      相关资源
      最近更新 更多