UILabel常用属性

父类

UILabel 继承自 UIView, 遵守 <NSCoding, UIContentSizeCategoryAdjusting> 两个协议

属性


/** Label 文字内容, 默认为 nil */
@property(nullable, nonatomic,copy)   NSString           *text;
/** Label 文字大小, 默认为 17 */
@property(null_resettable, nonatomic,strong) UIFont      *font;
/** Label 文字颜色, 默认为 黑色 */
@property(null_resettable, nonatomic,strong) UIColor     *textColor;
/** Label 阴影颜色, 默认为 nil */
@property(nullable, nonatomic,strong) UIColor            *shadowColor;
/** Label 阴影大小, 默认为 (0, -1) */
@property(nonatomic)        CGSize             shadowOffset;
/**
 Label 文字对其方式, 默认为 NSTextAlignmentLeft(左对齐)
 
 NSTextAlignment 枚举值:
 NSTextAlignmentLeft            左对齐
 NSTextAlignmentCenter          居中对齐
 NSTextAlignmentRight           右对齐
 NSTextAlignmentJustified       段落最后一行自然对齐对齐
 NSTextAlignmentNatural         脚本默认对齐方式
 */
@property(nonatomic)        NSTextAlignment    textAlignment;
/**
 Label 文字换行方式, 默认为 NSLineBreakByTruncatingTail(文字末尾加...)
 
 NSLineBreakMode 枚举值
 NSLineBreakByWordWrapping          保持单词完整性换行
 NSLineBreakByCharWrapping          按照字母换行
 NSLineBreakByClipping              裁剪边界
 NSLineBreakByTruncatingHead        最后一行前端隐藏
 NSLineBreakByTruncatingTail        最后一行后端隐藏
 NSLineBreakByTruncatingMiddle      最后一行中间隐藏
 */
@property(nonatomic)        NSLineBreakMode    lineBreakMode;

/** Label 富文本文字, 默认为 nil */
@property(nullable, nonatomic,copy)   NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0);

/** Label 文字高亮状态颜色, 用于其子类, 默认为 nil */
@property(nullable, nonatomic,strong)               UIColor *highlightedTextColor;
/** Label 文字高亮状态开关, 默认为 NO */
@property(nonatomic,getter=isHighlighted) BOOL     highlighted;
/** Label 用户交互开关, 默认为 NO */
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
/** Label 可用状态开关, 默认为 YES */
@property(nonatomic,getter=isEnabled)                BOOL enabled;


/** Label 显示行数, 默认为 1, 设置为 0 是无限行 */
@property(nonatomic) NSInteger numberOfLines;

/** 控件缩放相关属性 */
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;         // default is NO
@property(nonatomic) UIBaselineAdjustment baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines
@property(nonatomic) CGFloat minimumScaleFactor NS_AVAILABLE_IOS(6_0); // default is 0.0


/** 是否将宽于可用空间行的文字间距收紧, 默认为 NO */
@property(nonatomic) BOOL allowsDefaultTighteningForTruncation NS_AVAILABLE_IOS(9_0);

/** 覆盖绘制, 可在调用 super 之间调整 rect. label默认内容模式为UIViewContentModeRedraw */
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
- (void)drawTextInRect:(CGRect)rect;


/**
 用于自动布局
 如果非零,则在为多行标签确定-intrinsicContentSize时使用此方法
 */
@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);

常用方法

与父类 UIVIew 相同

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,871评论 1 32
  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 29,929评论 8 265
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,053评论 3 119
  • 一屋、两人、三餐、四季、下班回家好好吃顿饭吧! 真想和你吃一顿饭 仅仅只是一顿饭 来结束一只以来的喜欢 和对你无止...
    BOBO头女士阅读 9,556评论 0 0
  • 朋友整理的生活集锦18集,送给我的同学、同志、朋友,各位100%会受益。风雨人生,一路走来,我们实在不易,如今我们...
    淼鋒阅读 1,508评论 0 0

友情链接更多精彩内容