UILabel(FWUIKit)

@interface UILabel (FWUIKit)

/// 快速设置attributedText样式,设置后调用setText:会自动转发到setAttributedText:方法
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *fw_textAttributes NS_REFINED_FOR_SWIFT;

/// 快速设置文字的行高,优先级低于fwTextAttributes,设置后调用setText:会自动转发到setAttributedText:方法。小于0时恢复默认行高
@property (nonatomic, assign) CGFloat fw_lineHeight NS_REFINED_FOR_SWIFT;

/// 自定义内容边距,未设置时为系统默认。当内容为空时不参与intrinsicContentSize和sizeThatFits:计算,方便自动布局
@property (nonatomic, assign) UIEdgeInsets fw_contentInset NS_REFINED_FOR_SWIFT;

/// 纵向分布方式,默认居中
@property (nonatomic, assign) UIControlContentVerticalAlignment fw_verticalAlignment NS_REFINED_FOR_SWIFT;

/// 添加点击手势并自动识别NSLinkAttributeName|URL属性,点击高亮时回调链接,点击其它区域回调nil
- (void)fw_addLinkGestureWithBlock:(void (^)(id _Nullable link))block NS_REFINED_FOR_SWIFT;

/// 获取手势触发位置的文本属性,可实现行内点击效果等,allowsSpacing默认为NO空白处不可点击。为了识别更准确,attributedText需指定font
- (NSDictionary<NSAttributedStringKey, id> *)fw_attributesWithGesture:(UIGestureRecognizer *)gesture allowsSpacing:(BOOL)allowsSpacing NS_REFINED_FOR_SWIFT;

/// 快速设置标签
- (void)fw_setFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor NS_REFINED_FOR_SWIFT;

/// 快速设置标签并指定文本
- (void)fw_setFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor text:(nullable NSString *)text NS_REFINED_FOR_SWIFT;

/// 快速创建标签
+ (instancetype)fw_labelWithFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor NS_REFINED_FOR_SWIFT;

/// 快速创建标签并指定文本
+ (instancetype)fw_labelWithFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor text:(nullable NSString *)text NS_REFINED_FOR_SWIFT;

@end
extension UILabel: SkeletonViewDataSource

Undocumented

  • 快速设置attributedText样式,设置后调用setText:会自动转发到setAttributedText:方法

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *fw_textAttributes;
  • 快速设置文字的行高,优先级低于fwTextAttributes,设置后调用setText:会自动转发到setAttributedText:方法。小于0时恢复默认行高

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fw_lineHeight;
  • 自定义内容边距,未设置时为系统默认。当内容为空时不参与intrinsicContentSize和sizeThatFits:计算,方便自动布局

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets fw_contentInset;
  • 纵向分布方式,默认居中

    Declaration

    Objective-C

    @property (nonatomic) UIControlContentVerticalAlignment fw_verticalAlignment;
  • 添加点击手势并自动识别NSLinkAttributeName|URL属性,点击高亮时回调链接,点击其它区域回调nil

    Declaration

    Objective-C

    - (void)fw_addLinkGestureWithBlock:
        (nonnull void (^)(id _Nullable __strong))block;
  • 获取手势触发位置的文本属性,可实现行内点击效果等,allowsSpacing默认为NO空白处不可点击。为了识别更准确,attributedText需指定font

    Declaration

    Objective-C

    - (nonnull NSDictionary<NSAttributedStringKey, id> *)
        fw_attributesWithGesture:(nonnull UIGestureRecognizer *)gesture
                   allowsSpacing:(BOOL)allowsSpacing;
  • 快速设置标签

    Declaration

    Objective-C

    - (void)fw_setFont:(nullable UIFont *)font
             textColor:(nullable UIColor *)textColor;
  • 快速设置标签并指定文本

    Declaration

    Objective-C

    - (void)fw_setFont:(nullable UIFont *)font
             textColor:(nullable UIColor *)textColor
                  text:(nullable NSString *)text;
  • 快速创建标签

    Declaration

    Objective-C

    + (nonnull instancetype)fw_labelWithFont:(nullable UIFont *)font
                                   textColor:(nullable UIColor *)textColor;
  • 快速创建标签并指定文本

    Declaration

    Objective-C

    + (nonnull instancetype)fw_labelWithFont:(nullable UIFont *)font
                                   textColor:(nullable UIColor *)textColor
                                        text:(nullable NSString *)text;

Size

  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGSize fw_textSize
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGSize fw_attributedTextSize

UILabel+FWDebugger

  • 调试功能,打开后会在 label 第一行文字里把 descender、xHeight、capHeight、lineHeight 所在的位置以线条的形式标记出来。 对这些属性的解释可以看这篇文章 https://www.rightpoint.com/rplabs/ios-tracking-typography

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_showPrincipalLines;
  • 当打开 showPrincipalLines 时,通过这个属性控制线条的颜色,默认为 半透明红色

    Declaration

    Objective-C

    @property (nonatomic, strong) NS_REFINED_FOR_SWIFT UIColor *fw_principalLineColor;

UIKit+SkeletonView