UILabel is not auto-shrinking text to fit label size

后端 未结 17 616
感动是毒
感动是毒 2020-12-04 06:53

I have this strange issue, and im dealing with it for more than 8 hours now.. Depending on situation i have to calculate UILabels size dynamically,
e.g

17条回答
  •  旧巷少年郎
    2020-12-04 07:26

    In case you are still searching for a better solution, I think this is what you want:

    A Boolean value indicating whether the font size should be reduced in order to fit the title string into the label’s bounding rectangle (this property is effective only when the numberOfLines property is set to 1).

    When setting this property, minimumScaleFactor MUST be set too (a good default is 0.5).

    Swift

    var adjustsFontSizeToFitWidth: Bool { get set }
    

    Objective-C

    @property(nonatomic) BOOL adjustsFontSizeToFitWidth;
    

    A Boolean value indicating whether spacing between letters should be adjusted to fit the string within the label’s bounds rectangle.

    Swift

    var allowsDefaultTighteningForTruncation: Bool { get set }
    

    Objective-C

    @property(nonatomic) BOOL allowsDefaultTighteningForTruncation;
    

    Source.

提交回复
热议问题