QMUILabel

@interface QMUILabel : UILabel

QMUILabel支持通过contentEdgeInsets属性来实现类似padding的效果。

同时通过将canPerformCopyAction置为YES来开启长按复制文本的功能,复制 item 的文案可通过 menuItemTitleForCopyAction 修改,长按时label的背景色默认为highlightedBackgroundColor

  • 控制label内容的padding,默认为UIEdgeInsetsZero

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets contentEdgeInsets;

    Swift

    var contentEdgeInsets: UIEdgeInsets { get set }
  • 是否需要长按复制的功能,默认为 NO。 长按时的背景色通过highlightedBackgroundColor设置。

    Declaration

    Objective-C

    @property (nonatomic) BOOL canPerformCopyAction;

    Swift

    var canPerformCopyAction: Bool { get set }
  • 当 canPerformCopyAction 开启时,长按出来的菜单上的复制按钮的文本,默认为 nil,nil 时 menuItem 上的文字为“复制”

    Declaration

    Objective-C

    @property (nonatomic, copy) NSString *menuItemTitleForCopyAction;

    Swift

    var menuItemTitleForCopyAction: String! { get set }
  • label 在 highlighted 时的背景色,通常用于两种场景:

    1. 开启了 canPerformCopyAction 时,长按后的背景色
    2. 作为 subviews 放在 UITableViewCell 上,当 cell highlighted 时,label 也会触发 highlighted,此时背景色也会显示为这个属性的值

    默认为 nil

    Declaration

    Objective-C

    @property (nonatomic, strong) UIColor *highlightedBackgroundColor;

    Swift

    var highlightedBackgroundColor: UIColor! { get set }
  • 点击了“复制”后的回调

    Declaration

    Objective-C

    @property (nonatomic, copy) void (^)(QMUILabel *, NSString *) didCopyBlock;

    Swift

    var didCopyBlock: ((QMUILabel?, String?) -> Void)! { get set }