//// UILabel.h
// UIKit
//
// Copyright (c) 2006-2013, Apple Inc. All rights reserved.
//
@class UIColor, UIFont;
@class是放在interface中的,只是在引用一个类,将这个被引用类作为一个类型,在实现文件中,如果需要引用到被引用类的实体变量或者方法时,还需要使用#import方式引入被引用类。
NS_CLASS_AVAILABLE_IOS(2_0)
@interface UILabel : UIView@property(nonatomic,copy) NSString *text; // default is nil
设置此属性---将会在Label上显示文字,内容为text
@property(nonatomic,retain) UIFont *font; // default is nil (system font 17 plain)
设置此属性---改变text的大小,默认是17号
label.font = [UIFont systemFontOfSize:20]; //⼀一般方法
label.font = [UIFont boldSystemFontOfSize:20]; //加粗方法
label.font = [UIFont fontWithName:@"DBLCDTempBlack" size:25]; //指定字体和大小
@property(nonatomic,retain) UIColor *textColor; // default is nil (text draws black)
设置此属性---改变text的颜色,默认是黑色
@property(nonatomic,retain) UIColor *shadowColor; // default is nil (no shadow)
设置此属性---在text的后面添加阴影效果并设置颜色
@property(nonatomic) CGSize shadowOffset; // default is CGSizeMake(0, -1) -- a top shadow
设置此属性---text的阴影与本身的位置偏差
@property(nonatomic) NSTextAlignment textAlignment; // default is NSTextAlignmentLeft
NSTextAlignmentLeft—-靠左
NSTextAlignmentCenter –中间
NSTextAlignmentRight—靠右
设置此属性---text的对齐方式
@property(nonatomic) NSLineBreakMode lineBreakMode; // default is NSLineBreakByTruncatingTail. used for single and multiple lines of text
设置此属性---text过长时的显示格式
NSLineBreakByCharWrapping;以字符为显示单位显示,后面部分省略不显示。
NSLineBreakByClipping;剪切与文本宽度相同的内
容长度,后半部分被删除。
NSLineBreakByTruncatingHead;前面部分文字
以……方式省略,显示尾部文字内容。
NSLineBreakByTruncatingMiddle;中间的内容
以……方式省略,显示头尾的文字内容。
NSLineBreakByTruncatingTail;结尾部分的内容
以……方式省略,显示头的文字内容。
NSLineBreakByWordWrapping;以单词为显示单位显示,后面部分省略不显示。
// the underlying attributed string drawn by the label, if set, the label ignores the properties above.
@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
//attributedText:设置富文本。
NSString *text = @"XibHua";
NSMutableAttributedString *textLabelStr =[[NSMutableAttributedString alloc]initWithString:text];
[textLabelStr setAttributes:@{NSForegroundColorAttributeName :[UIColor orangeColor],NSFontAttributeName :[UIFont systemFontOfSize:17]} range:NSMakeRange(0,3)];
label.attributedText = textLabelStr;
显示结果为[XibHua]
// the 'highlight' property is used by subclasses for such things as pressed states. it's useful to make it part of the base class as a user property
@property(nonatomic,retain) UIColor *highlightedTextColor; // default is nil
设置此属性---text高亮状态的字体颜色
@property(nonatomic,getter=isHighlighted) BOOL highlighted; // default is NO
设置此属性---text是否处于高亮
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is NO
@property(nonatomic,getter=isEnabled) BOOL enabled;
设置此属性---text 只是决定了Label的绘制方式,将它设置为NO将会使文本变暗,表示它没有激活,这时向它设置颜色值是无效的
// default is YES. changes how the label is drawn
// this determines the number of lines to draw and what to do when sizeToFit is called. default value is 1 (single line). A value of 0 means no limit
// if the height of the text reaches the # of lines or the height of the view is less than the # of lines allowed, the text will be
// truncated using the line break mode.
@property(nonatomic) NSInteger numberOfLines;
设置此属性---text最多显示行数,如果为0则表示多行
// these next 3 property allow the label to be autosized to fit a certain width by scaling the font size(s) by a scaling factor >= the minimum scaling factor
// and to specify how the text baseline moves when it needs to shrink the font.
@property(nonatomic) BOOL adjustsFontSizeToFitWidth; // default is NO
未发现设置后的实际效果
@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth NS_DEPRECATED_IOS(6_0,7_0); // deprecated - hand tune by using NSKernAttributeName to affect tracking
已经弃用,以后利用NSKernAttributeName来改变
@property(nonatomic) CGFloat minimumFontSize NS_DEPRECATED_IOS(2_0, 6_0); // NOTE: deprecated - use minimumScaleFactor. default is 0.0
已经弃用
@property(nonatomic) UIBaselineAdjustment baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines
未发现设置后的实际效果
@property(nonatomic) CGFloat minimumScaleFactor NS_AVAILABLE_IOS(6_0); // default is 0.0
// override points. can adjust rect before calling super.
// label has default content mode of UIViewContentModeRedraw
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
- (void)drawTextInRect:(CGRect)rect;
以上俩个方法一般用于重写Label.
// Support for constraint-based layout (auto layout)
// If nonzero, this is used when determining -intrinsicContentSize for multiline labels
@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);
//到达此属性设置的宽度就换行
@end
网友评论