您的位置:首页 > 产品设计 > UI/UE

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

2015-10-26 10:05 429 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: