Getting UILabel to produce an ellipsis rather than shrinking the font

前端 未结 4 1027
无人及你
无人及你 2020-12-03 04:49

When I dynamically change the text of a UILabel I would prefer to get an ellipsis (dot, dot, dot) rather then have the text be automatically resized. How does one do this?

4条回答
  •  盖世英雄少女心
    2020-12-03 05:23

    Set the following properties:

    Objective C

    label.adjustsFontSizeToFitWidth = NO;
    label.lineBreakMode = NSLineBreakByTruncatingTail;
    

    Swift

    label.adjustsFontSizeToFitWidth = false
    label.lineBreakMode = .byTruncatingTail
    

    You can also set these properties in interface builder.

提交回复
热议问题