// NSFontAttributeName? ? ? ? ? ? ? ? 設置字體屬性,默認值:字體:Helvetica(Neue) 字號:12
//?NSForegroundColorAttributeNam??????設置字體顏色,取值為?UIColor對象,默認值為黑色
//?NSBackgroundColorAttributeName?????設置字體所在區域背景顏色,取值為?UIColor對象,默認值為nil,?透明色
//?NSLigatureAttributeName????????????設置連體屬性,取值為NSNumber?對象(整數),0?表示沒有連體字符,1?表示使用默認的連體字符
//?NSKernAttributeName????????????????設定字符間距,取值為?NSNumber?對象(整數),正值間距加寬,負值間距變窄
//?NSStrikethroughStyleAttributeName??設置刪除線,取值為?NSNumber?對象(整數)
//?NSStrikethroughColorAttributeName??設置刪除線顏色,取值為?UIColor?對象,默認值為黑色
//?NSUnderlineStyleAttributeName??????設置下劃線,取值為?NSNumber?對象(整數),枚舉常量?NSUnderlineStyle中的值,與刪除線類似
//?NSUnderlineColorAttributeName??????設置下劃線顏色,取值為?UIColor?對象,默認值為黑色
//?NSStrokeWidthAttributeName?????????設置筆畫寬度,取值為?NSNumber?對象(整數),負值填充效果,正值中空效果
//?NSStrokeColorAttributeName?????????填充部分顏色,不是字體顏色,取值為?UIColor?對象
//?NSShadowAttributeName??????????????設置陰影屬性,取值為?NSShadow?對象
//?NSTextEffectAttributeName??????????設置文本特殊效果,取值為?NSString?對象,目前只有圖版印刷效果可用:
//?NSBaselineOffsetAttributeName??????設置基線偏移值,取值為?NSNumber?(float),正值上偏,負值下偏
//?NSObliquenessAttributeName?????????設置字形傾斜度,取值為?NSNumber?(float),正值右傾,負值左傾
//?NSExpansionAttributeName???????????設置文本橫向拉伸屬性,取值為?NSNumber?(float),正值橫向拉伸文本,負值橫向壓縮文本
//?NSWritingDirectionAttributeName????設置文字書寫方向,從左向右書寫或者從右向左書寫
//?NSVerticalGlyphFormAttributeName???設置文字排版方向,取值為?NSNumber?對象(整數),0?表示橫排文本,1?表示豎排文本
//?NSLinkAttributeName????????????????設置鏈接屬性,點擊后調用瀏覽器打開指定URL地址
//?NSAttachmentAttributeName??????????設置文本附件,取值為NSTextAttachment對象,常用于文字圖片混排
//?NSParagraphStyleAttributeName??????設置文本段落排版格式,取值為?NSParagraphStyle?對象
//???NSParagraphStyleAttributeName?段落的風格(設置首行,行間距,對齊方式什么的)看自己需要什么屬性,寫什么
NSMutableParagraphStyle*paragraphStyle?=?[[NSMutableParagraphStylealloc]init];
paragraphStyle.lineSpacing=10;//?字體的行間距
paragraphStyle.firstLineHeadIndent=20.0f;//首行縮進
paragraphStyle.alignment=?NSTextAlignmentJustified;//(兩端對齊的)文本對齊方式:(左,中,右,兩端對齊,自然)
paragraphStyle.lineBreakMode=?NSLineBreakByTruncatingTail;//結尾部分的內容以……方式省略?(?"...wxyz"?,"abcd..."?,"ab...yz")
paragraphStyle.headIndent=20;//整體縮進(首行除外)
paragraphStyle.tailIndent=20;//
paragraphStyle.minimumLineHeight=10;//最低行高
paragraphStyle.maximumLineHeight=20;//最大行高
paragraphStyle.paragraphSpacing=15;//段與段之間的間距
paragraphStyle.paragraphSpacingBefore=22.0f;//段首行空白空間/*?Distance?between?the?bottom?of?the?previous?paragraph?(or?the?end?of?its?paragraphSpacing,?if?any)
and?the?top?of?this?paragraph.?*/
paragraphStyle.baseWritingDirection=?NSWritingDirectionLeftToRight;//從左到右的書寫方向(一共??三種)
paragraphStyle.lineHeightMultiple=15;/*?Natural?line?height?is?multiplied?by?this?factor?(if?positive)
before?being?constrained?by?minimum?and?maximum?line?height.?*/
paragraphStyle.hyphenationFactor=1;//連字屬性?在iOS,唯一支持的值分別為0和1
_descAtt?=?[[NSMutableAttributedStringalloc]initWithString:_model.desc];
UIFont*descFont?=?[UIFontPingFangSC_Regular_WithSize:12];
NSMutableParagraphStyle*descStyle?=?[[NSMutableParagraphStylealloc]init];
[descStylesetLineSpacing:1];//行間距
CGSize?descSize?=?[_model.descboundingRectWithSize:CGSizeMake(w,?MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:descFont,
NSParagraphStyleAttributeName?:descStyle}
context:nil].size;
#define UILABEL_LINE_SPACE6
#define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height
//給UILabel設置行間距和字間距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
NSMutableParagraphStyle*paraStyle = [[NSMutableParagraphStylealloc]init];
paraStyle.lineBreakMode=NSLineBreakByCharWrapping;
paraStyle.alignment=NSTextAlignmentLeft;
paraStyle.lineSpacing=UILABEL_LINE_SPACE; //設置行間距
paraStyle.hyphenationFactor=1.0;
paraStyle.firstLineHeadIndent=0.0;
paraStyle.paragraphSpacingBefore=0.0;
paraStyle.headIndent=0;
paraStyle.tailIndent=0;
//設置字間距NSKernAttributeName:@1.5f
NSDictionary*dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@1.5f
};
NSAttributedString*attributeStr = [[NSAttributedStringalloc]initWithString:strattributes:dic];
label.attributedText= attributeStr;
}
//計算UILabel的高度(帶有行間距的情況)
-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
NSMutableParagraphStyle*paraStyle = [[NSMutableParagraphStylealloc]init];
paraStyle.lineBreakMode=NSLineBreakByCharWrapping;
paraStyle.alignment=NSTextAlignmentLeft;
paraStyle.lineSpacing=UILABEL_LINE_SPACE;
paraStyle.hyphenationFactor=1.0;
paraStyle.firstLineHeadIndent=0.0;
paraStyle.paragraphSpacingBefore=0.0;
paraStyle.headIndent=0;
paraStyle.tailIndent=0;
NSDictionary*dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@1.5f
};
CGSizesize = [strboundingRectWithSize:CGSizeMake(width,HEIGHT)options:NSStringDrawingUsesLineFragmentOriginattributes:diccontext:nil].size;
returnsize.height;
}