[iOS]在xib中设置YYLabel自适应高度

1、直接在xib中是无法设置YYLabel的,有个方法就是:

  • 可以先自定义一个CustomLabel继承自UILabel
  • 在拖动一个UILabel的控件到xib中,设置CustomClass为:CustomLabel
  • 拖动这个控件,连线。
  • 重要步骤:修改CustomLabel,父类为:YYLabel

2、做完了上面步骤,进入xib,点击CustomLabel,设置它的约束。

3、要想YYLabel自适应高度,需要设置preferredMaxLayoutWidth值。

在对YYLabel应用自动布局的时候设置此属性可以影响内容的换行。

@discussion

This property affects the size of the label when layout constraints are applied to it. During layout, if the text extends beyond the width  specified by this property, the additional text is flowed to one or more new lines, thereby increasing the height of the label. If the text is vertical form, this value will match to text height.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值