@property(nullable, nonatomic,copy) NSString *text;
//設(shè)置字體(默認(rèn)為17號(hào))
@property(null_resettable, nonatomic,strong) UIFont *font;
//設(shè)置字體顏色(默認(rèn)黑色)
@property(null_resettable, nonatomic,strong) UIColor *textColor;
//設(shè)置陰影顏色
@property(nullable, nonatomic,strong) UIColor *shadowColor;
//設(shè)置陰影偏移量
@property(nonatomic) CGSize shadowOffset;
//設(shè)置文字對(duì)齊方式
@property(nonatomic) NSTextAlignment textAlignment;
/*
typedef NS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft = 0, //左對(duì)齊
NSTextAlignmentCenter = 1, // 居中
NSTextAlignmentRight = 2, // 右對(duì)齊
NSTextAlignmentJustified = 3, // 充滿View來(lái)顯示
NSTextAlignmentNatural = 4, // 根據(jù)顯示的文字特性對(duì)齊
} NS_ENUM_AVAILABLE_IOS(6_0);
*/
//設(shè)置段落樣式
@property(nonatomic) NSLineBreakMode lineBreakMode; // default is
/*
typedef NS_ENUM(NSInteger, NSLineBreakMode) {
NSLineBreakByWordWrapping = 0, // 在字邊界處換行,默認(rèn)
NSLineBreakByCharWrapping, // 在字符邊界處換行
NSLineBreakByClipping, // 簡(jiǎn)單剪輯
NSLineBreakByTruncatingHead, // 截?cái)嘣谛惺?"...wxyz"
NSLineBreakByTruncatingTail, // 截尾在行尾:"abcd..."
NSLineBreakByTruncatingMiddle // 截?cái)嘈兄虚g:“ab ... yz”
}
*/
//富文本,默認(rèn)nil
@property(nullable, nonatomic,copy) NSAttributedString *attributedText;
//設(shè)置高亮顏色
@property(nullable, nonatomic,strong) UIColor *highlightedTextColor;
@property(nonatomic,getter=isHighlighted) BOOL highlighted;
//用戶是否可交互
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
@property(nonatomic,getter=isEnabled) BOOL enabled;
//顯示行數(shù) 默認(rèn)1行
@property(nonatomic) NSInteger numberOfLines;
//設(shè)置基線
@property(nonatomic) UIBaselineAdjustment baseline;
/*
typedef NS_ENUM(NSInteger, UIBaselineAdjustment) {
UIBaselineAdjustmentAlignBaselines = 0, //默認(rèn)缩幸,文本最上端與中線對(duì)齊。
UIBaselineAdjustmentAlignCenters, //文本中線與label中線對(duì)齊肌访。
UIBaselineAdjustmentNone, //文本最低端與label中線對(duì)齊女气。
};
*/
//設(shè)置字體大小適應(yīng)label寬度
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
//設(shè)置最小收縮比例
@property(nonatomic) CGFloat minimumScaleFactor;
//改變字母之間的間距來(lái)適應(yīng)Label大小
@property(nonatomic) BOOL allowsDefaultTighteningForTruncation;
// 計(jì)算UILabel隨字體多行后的高度
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
- (void)drawTextInRect:(CGRect)rect;
//最大約束寬
@property(nonatomic) CGFloat preferredMaxLayoutWidth;
調(diào)整Label中text的行間距
NSString * textStr = @"這是測(cè)試UILabel行間距的text肮之。這是測(cè)試UILabel行間距的text瘤袖。\n這是測(cè)試UILabel行間距的text衣摩。\n這是測(cè)試UILabel行間距的text。這是測(cè)試UILabel行間距的text捂敌。這是測(cè)試UILabel行間距的text艾扮。這是測(cè)試UILabel行間距的text。";
UILabel * cLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 280, 200)];
cLabel.numberOfLines = 0;
cLabel.font = [UIFont systemFontOfSize:16];
cLabel.textColor = [UIColor grayColor];
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:textStr];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:8];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [textStr length])];
[cLabel setAttributedText:attributedString1];
[cLabel sizeToFit];
[self.view addSubview:cLabel];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者