iOS-UIKit( UILabel.h - -解读)


NS_ASSUME_NONNULL_BEGIN


@class UIColor,UIFont;


NS_CLASS_AVAILABLE_IOS(2_0)@interface UILabel :UIView <NSCoding>

//设置和读取文本内容,默认为nil

/*

 竖排文字显示每个文字加一个换行符,这是最方便和简单的实现方式。

 label.text = @"\n\n\n\n\n\n";

 label.numberOfLines = [label.text length];

 */

@property(nullable,nonatomic,copy)NSString *text;

//设置字体大小,默认17

@property(null_resettable,nonatomic,strong)UIFont*font;

//设置文字颜色,默认为黑色

@property(null_resettable,nonatomic,strong)UIColor*textColor;

//设置阴影颜色 

@property(nullable,nonatomic,strong)UIColor*shadowColor;

//设置阴影偏移量

@property(nonatomic)CGSize shadowOffset;

//设置标签文本对齐方式。

@property(nonatomic)NSTextAlignment textAlignment;

//设置文字过长时的显示格式

/*

 label.lineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显

 示,后面部分省略不显示。

 label.lineBreakMode = NSLineBreakByClipping;剪切与文本宽度相同的内

 容长度,后半部分被删除。

 label.lineBreakMode = NSLineBreakByTruncatingHead;前面部分文字

 ……方式省略,显示尾部文字内容。

 label.lineBreakMode = NSLineBreakByTruncatingMiddle;中间的内容

 ……方式省略,显示头尾的文字内容。

 label.lineBreakMode = NSLineBreakByTruncatingTail;结尾部分的内容

 ……方式省略,显示头的文字内容。

 label.lineBreakMode = NSLineBreakByWordWrapping;以单词为显示单位显

 示,后面部分省略不显示。

 */

@property(nonatomic)NSLineBreakMode lineBreakMode;

//设置标签属性文本。

/*

 NSMutableAttributedString*attriString=[[NSMutableAttributedString alloc]initWithString:@"this is test!"];

 [attriString addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, 4)];

 [attriString addAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} range:NSMakeRange(8, 4)];

 //改变this的字体,value必须是一个CTFontRef

 [attriString addAttribute:(NSString *)kCTFontAttributeName

 value:(id)CFBridgingRelease(CTFontCreateWithName((CFStringRef)[UIFont boldSystemFontOfSize:14].fontName,14,NULL))range:NSMakeRange(0, 4)];

 //this加上下划线,value可以在指定的枚举中选择

 [attriString addAttribute:(NSString *)kCTUnderlineStyleAttributeName

 value:(id)[NSNumber numberWithInt:kCTUnderlineStyleDouble]

 range:NSMakeRange(0, 4)];

 UILabel*Label=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];

 Label.attributedText=attriString;

 [self.view addSubview:Label];

 */

@property(nullable,nonatomic,copy)NSAttributedString *attributedText 

//高亮显示时的文本颜色

@property(nullable,nonatomic,strong)UIColor *highlightedTextColor;

//是否高亮显示

@property(nonatomic,getter=isHighlighted)BOOL highlighted; 

//是否可以与用户交互

@property(nonatomic,getter=isUserInteractionEnabled)BOOL userInteractionEnabled; 

//只是决定了Label的绘制方式,将它设置为NO将会使文本变暗,表示它没有激活,这时向它设置颜色值是无效的。

@property(nonatomic,getter=isEnabled)BOOL enabled;

//标签最多显示行数,如果为0则表示多行。

@property(nonatomic)NSInteger numberOfLines;

//设置字体大小适应label宽度 

@property(nonatomic)BOOL adjustsFontSizeToFitWidth; 

//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为。

/*

 UIBaselineAdjustmentAlignBaselines = 0,默认,文本最上端与中线对齐。

 UIBaselineAdjustmentAlignCenters,  文本中线与label中线对齐。

 UIBaselineAdjustmentNone, 文本最低端与label中线对齐。

 */

@property(nonatomic)UIBaselineAdjustment baselineAdjustment;

//设置最小收缩比例,如果Label宽度小于文字长度时,文字进行收缩,收缩超过比例后,停止收缩。

@property(nonatomic)CGFloat minimumScaleFactor NS_AVAILABLE_IOS(6_0); 

@property(nonatomic)BOOL allowsDefaultTighteningForTruncation NS_AVAILABLE_IOS(9_0); 


- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;


- (void)drawTextInRect:(CGRect)rect;


@property(nonatomic)CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);

//设置最小收缩字号,如果Label宽度小于文字长度时,文字字号减小,低于设定字号后,不再减小。6.0以后不再使用了。

@property(nonatomic)CGFloat minimumFontSize NS_DEPRECATED_IOS(2_0, 6_0);

//改变字母之间的间距来适应Label大小

@property(nonatomic)BOOL adjustsLetterSpacingToFitWidth NS_DEPRECATED_IOS(6_0,7_0);


@end


NS_ASSUME_NONNULL_END


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值