字体属性

字体属性设置示例:

if(color ==nil) {

color = [NSColor redColor];

}

NSFont *font = button.font;

NSMutableParagraphStyle *centredStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];

[centredStyle setAlignment:NSCenterTextAlignment];

NSDictionary * attrs = [NSDictionary dictionaryWithObjectsAndKeys:font,

NSFontAttributeName,

color,

NSForegroundColorAttributeName,

centredStyle,

NSParagraphStyleAttributeName,

nil];

NSAttributedString * attributedString = [[NSAttributedString alloc]initWithString:[button title] attributes:attrs];

[button setAttributedTitle:attributedString];

以下为参数的设定

// NSFontAttributeName                设置字体属性,默认值:字体:Helvetica(Neue) 字号:12  

//NSForegroundColorAttributeName 设置字体颜色,取值为 UIColor,默认为黑色  

NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };  

 NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };  

 NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] };      

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; 

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


// NSForegroundColorAttributeNam      设置字体颜色,取值为 UIColor对象,默认值为黑色

//NSForegroundColorAttributeName 设置字体颜色,取值为 UIColor,默认为黑色

NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };  

 NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };  

 NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] };      

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; 

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];        


 // NSBackgroundColorAttributeName    设置字体所在区域背景颜色,取值为 UIColor对象,默认值为nil, 透明色  

NSDictionary *attrDict4 = @{ NSBackgroundColorAttributeName: [UIColor orangeColor] }; 

NSDictionary *attrDict5 = @{ NSBackgroundColorAttributeName: [UIColor redColor] }; 

NSDictionary *attrDict6 = @{ NSBackgroundColorAttributeName: [UIColor cyanColor] };     

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict4]; 

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict5]; 

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict6];

NSForegroundColorAttributeName 和 NSBackgroundColorAttributeName 的低位是相等的,跟前面介绍的 textColor 一样,哪个属性最后一次赋值,就会冲掉前面的效果


// NSLigatureAttributeName            设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符  

//NSLigatureAttributeName 设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符,  //  2 表示使用所有连体符号,默认值为 1(iOS 不支持 2)      

NSString *ligatureStr = @"flush";      

NSDictionary *attrDict1 = @{ NSLigatureAttributeName: [NSNumber numberWithInt: 0],                                

NSFontAttributeName: [UIFont fontWithName: @"futura" size: 30] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: ligatureStr attributes: attrDict1];      

NSDictionary *attrDict2 = @{ NSLigatureAttributeName: @(1),                                NSFontAttributeName: [UIFont fontWithName: @"futura" size: 30]                                };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: ligatureStr attributes: attrDict2];

由于要展示连体字符,所以将前面使用的带有中文的字符串换成 flush

NSLigatureAttributeName的取值为NSNumber对象,所以不能直接将一个整数值赋给它,创建 NSNumber 对象的方法有很多,或者可以简写成 @(int)


// NSKernAttributeName                设定字符间距,取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄  

NSDictionary *attrDict1 = @{ NSKernAttributeName: @(-3),                                NSFontAttributeName: [UIFont systemFontOfSize: 20]};  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSKernAttributeName: @(0),                                NSFontAttributeName: [UIFont systemFontOfSize: 20]};  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSKernAttributeName: @(10),                                NSFontAttributeName: [UIFont systemFontOfSize: 20]};  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


// NSStrikethroughStyleAttributeName  设置删除线,取值为 NSNumber 对象(整数)  

//NSStrikethroughStyleAttributeName 设置删除线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值  

 // NSUnderlineStyleNone  不设置删除线  

// NSUnderlineStyleSingle 设置删除线为细单实线  

// NSUnderlineStyleThick  设置删除线为粗单实线  

// NSUnderlineStyleDouble 设置删除线为细双实线        

 NSDictionary *attrDict1 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),                                

NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick),                                

NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleDouble),                                

NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];

取值为 0 - 7时,效果为单实线,随着值得增加,单实线逐渐变粗,取值为 9 - 15时,效果为双实线,取值越大,双实线越粗

虽然使用了枚举常量,但是枚举常量的本质仍为整数,所以同样必须先转化为 NSNumber 才能使用

删除线和下划线使用相同的枚举常量作为其属性值

目前iOS中只有上面列出的4中效果,虽然我们能够在头文件中发现其他更多的取值,但是使用后没有任何效果


// NSStrikethroughColorAttributeName  设置删除线颜色,取值为 UIColor 对象,默认值为黑色     

NSDictionary *attrDict1 = @{ NSStrikethroughColorAttributeName: [UIColor blueColor],                                

NSStrikethroughStyleAttributeName: @(1),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSStrikethroughColorAttributeName: [UIColor orangeColor],                                

NSStrikethroughStyleAttributeName: @(3),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSStrikethroughColorAttributeName: [UIColor greenColor],                                

NSStrikethroughStyleAttributeName: @(7),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSUnderlineStyleAttributeName      设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似  

 NSDictionary *attrDict1 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),                                

NSFontAttributeName: [UIFont systemFontOfSize:20] }; 

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleThick), NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleDouble),NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSUnderlineColorAttributeName      设置下划线颜色,取值为 UIColor 对象,默认值为黑色  

NSDictionary *attrDict1 = @{ NSUnderlineColorAttributeName: [UIColor blueColor],NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSUnderlineColorAttributeName: [UIColor orangeColor],NSUnderlineStyleAttributeName: @(NSUnderlineStyleThick),NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSUnderlineColorAttributeName: [UIColor greenColor],NSUnderlineStyleAttributeName: @(NSUnderlineStyleDouble),NSFontAttributeName: [UIFont systemFontOfSize:20] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


// NSStrokeWidthAttributeName        设置笔画宽度,取值为 NSNumber 对象(整数),负值填充效果,正值中空效果  

NSDictionary *attrDict1 = @{ NSStrokeWidthAttributeName: @(-3),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSStrokeWidthAttributeName: @(0),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSStrokeWidthAttributeName: @(3),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSStrokeColorAttributeName        填充部分颜色,不是字体颜色,取值为 UIColor 对象  

NSDictionary *attrDict1 = @{ NSStrokeWidthAttributeName: @(-3),                                NSStrokeColorAttributeName: [UIColor orangeColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSStrokeWidthAttributeName: @(0),                                NSStrokeColorAttributeName: [UIColor blueColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] }; 

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];        

 NSDictionary *attrDict3 = @{ NSStrokeWidthAttributeName: @(3),                                NSStrokeColorAttributeName: [UIColor greenColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSShadowAttributeName              设置阴影属性,取值为 NSShadow 对象

NSShadow *shadow1 = [[NSShadow alloc] init];  

//NSShadow 对象比较简单,只有3个属性:阴影颜色,模糊半径和偏移  shadow1.shadowOffset = CGSizeMake(3, 3);//阴影偏移(X方向偏移和Y方向偏移)  

 shadow1.shadowBlurRadius = 0.5;//模糊半径  

 shadow1.shadowColor = [UIColor orangeColor];  //阴影颜色      

NSShadow *shadow2 = [[NSShadow alloc] init];  

 shadow2.shadowOffset = CGSizeMake(3, 16);  shadow2.shadowBlurRadius = 2.5;  

 shadow2.shadowColor = [UIColor purpleColor];      

NSShadow *shadow3 = [[NSShadow alloc] init];  

 shadow3.shadowOffset = CGSizeMake(16, 3);  

 shadow3.shadowBlurRadius = 4.0;  

 shadow3.shadowColor = [UIColor blueColor];      

NSDictionary *attrDict1 = @{ NSShadowAttributeName: shadow1,                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSShadowAttributeName: shadow2,                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSShadowAttributeName: shadow3,                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSTextEffectAttributeName          设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用:

//NSTextEffectLetterpressStyle(凸版印刷效果),适用于iOS 7.0及以上        

NSDictionary *attrDict1 = @{ NSTextEffectAttributeName: NSTextEffectLetterpressStyle,                                NSForegroundColorAttributeName: [UIColor grayColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

 _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ //NSTextEffectAttributeName: NSTextEffectLetterpressStyle,                                NSForegroundColorAttributeName: [UIColor grayColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

 _label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSTextEffectAttributeName: NSTextEffectLetterpressStyle,                                NSForegroundColorAttributeName: [UIColor blueColor],                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

 _label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


// NSBaselineOffsetAttributeName      设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏  

NSDictionary *attrDict1 = @{ NSBaselineOffsetAttributeName: @(-10),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSBaselineOffsetAttributeName: @(0),                              NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSBaselineOffsetAttributeName: @(10),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSObliquenessAttributeName        设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾  

NSDictionary *attrDict1 = @{ NSObliquenessAttributeName: @(-0.5),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSObliquenessAttributeName: @(0),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSObliquenessAttributeName: @(0.8),                                NSFontAttributeName: [UIFont systemFontOfSize:30] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSExpansionAttributeName          设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本  

NSDictionary *attrDict1 = @{ NSExpansionAttributeName: @(-1),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSExpansionAttributeName: @(0),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSExpansionAttributeName: @(0.6),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSWritingDirectionAttributeName    设置文字书写方向,从左向右书写或者从右向左书写  

//NSWritingDirectionAttributeName 设置文字书写方向,取值为以下组合      //@[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionEmbedding)]  //@[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionOverride)]  //@[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionEmbedding)]  //@[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride)]      

NSDictionary *attrDict1 = @{ NSWritingDirectionAttributeName: @[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionEmbedding)],                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];      

NSDictionary *attrDict2 = @{ NSWritingDirectionAttributeName: @[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride)],                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSWritingDirectionAttributeName: @[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionOverride)],                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSVerticalGlyphFormAttributeName  设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本  

//在 iOS 中,总是使用横排文本,0 以外的值都未定义      

NSDictionary *attrDict1 = @{ NSVerticalGlyphFormAttributeName: @(-10),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];        

 NSDictionary *attrDict2 = @{ NSVerticalGlyphFormAttributeName: @(0),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];      

NSDictionary *attrDict3 = @{ NSVerticalGlyphFormAttributeName: @(10),                                NSFontAttributeName: [UIFont systemFontOfSize:20] };  

_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];


 // NSLinkAttributeName                设置链接属性,点击后调用浏览器打开指定URL地址  

链接属性点击将启动浏览器打开一个URL地址,中间用到一个代理函数,UILabel 和 UITextField 无法使用该属性,所以只能用UITextView来做示例。

NSDictionary *attrDict1 = @{ NSLinkAttributeName: [NSURL URLWithString: @"http://www.baidu.com"],                                NSFontAttributeName: [UIFont systemFontOfSize:20] };     

_textview01.editable = NO;        //必须禁止输入,否则点击将弹出输入键盘 

_textview01.scrollEnabled = NO;  //可选 

_textview01.delegate = self;      //必须设置,否则代理函数不会被回调     

_textview01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];

代理函数

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{      
NSLog(@"textView is clicked...");      
return YES;  }

// NSAttachmentAttributeName          设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排  

NSTextAttachment *textAttachment01 = [[NSTextAttachment alloc] init];  

textAttachment01.image = [UIImage imageNamed: @"10000.jpeg"];  //设置图片源  

textAttachment01.bounds = CGRectMake(0, 0, 30, 30);          //设置图片位置和大小  

 NSMutableAttributedString *attrStr01 = [[NSMutableAttributedString alloc] initWithString: originStr];      

[attrStr01 addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 25] range: NSMakeRange(0, originStr.length)];  NSAttributedString *attrStr11 = [NSAttributedString attributedStringWithAttachment: textAttachment01];      

[attrStr01 insertAttributedString: attrStr11 atIndex: 2];  //NSTextAttachment占用一个字符长度,插入后原字符串长度增加1      

_label01.attributedText = attrStr01;        

 NSTextAttachment *textAttachment02 = [[NSTextAttachment alloc] init];  

textAttachment02.image = [UIImage imageNamed: @"10000.jpeg"];  //设置图片源  

textAttachment02.bounds = CGRectMake(0, -10, 30, 40);          //设置图片位置和大小  

 NSMutableAttributedString *attrStr02 = [[NSMutableAttributedString alloc] initWithString: originStr];      

[attrStr02 addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 25] range: NSMakeRange(0, originStr.length)];  

 NSAttributedString *attrStr12 = [NSAttributedString attributedStringWithAttachment: textAttachment02];      

[attrStr02 insertAttributedString: attrStr12 atIndex: 6];      

_label02.attributedText = attrStr02;      

NSTextAttachment *textAttachment03 = [[NSTextAttachment alloc] init];  

textAttachment03.image = [UIImage imageNamed: @"10000.jpeg"];  //设置图片源  

textAttachment03.bounds = CGRectMake(0, -6, 50, 30);          //设置图片位置和大小  

 NSMutableAttributedString *attrStr03 = [[NSMutableAttributedString alloc] initWithString: originStr];     

[attrStr03 addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 25] range: NSMakeRange(0, originStr.length)];  

 NSAttributedString *attrStr13 = [NSAttributedString attributedStringWithAttachment: textAttachment03];      

[attrStr03 insertAttributedString: attrStr13 atIndex: 8];      

_label03.attributedText = attrStr03;


// NSParagraphStyleAttributeName      设置文本段落排版格式,取值为 NSParagraphStyle 对象

设置文本段落排版格式,取值为 NSParagraphStyle/NSMutableParagraphStyle 对象,可以设置如下属性:

// alignment              对齐方式,取值枚举常量 NSTextAlignment  

enum {        

NSTextAlignmentLeft      = 0, 

NSTextAlignmentCenter    = 1,

NSTextAlignmentRight    = 2, 

NSTextAlignmentJustified = 3,

NSTextAlignmentNatural  = 4,}; 

 // firstLineHeadIndent    首行缩进,取值 float  

// headIndent              缩进,取值 float  

// tailIndent              尾部缩进,取值 float  注意距离是从行首算起

// lineHeightMultiple      可变行高,乘因数,取值 float  // maximumLineHeight      最大行高,取值 float 

行高倍数因子,大于1行高变小,小于1行高变小,实际上字体大小不会改变,改变的时行间距

 // minimumLineHeight      最小行高,取值 float  

//  manimumLineHeight    最大行高,取值 float

最大行高,若其值小于默认行高,则行间距变小,若其值大于默认行高,则不会引起任何变化

最小行高,若其值大于默认行高,则行间距变大,若其值小于默认行高,则不会引起任何变化

 // lineSpacing            行距,取值 float 

行距,取值为 float,可正可负,正值增加行距,负值减小行距

// paragraphSpacing        段距,取值 float  负值无效,取0值

 // paragraphSpacingBefore  段首空间,取值 float  

 //baseWritingDirection    句子方向,取值枚举常量 NSWritingDirection 

enum {        

NSWritingDirectionNatural = -1,        

NSWritingDirectionLeftToRight =  0, 

NSWritingDirectionRightToLeft =  1 };

 // lineBreakMode          断行方式,取值枚举常量 NSLineBreakMode  

enum {

NSLineBreakByWordWrapping = 0, //自动换行,单词切断 

NSLineBreakByCharWrapping,    //自动换行,字母切断 

NSLineBreakByClipping,        //非自动换行,不切断 

NSLineBreakByTruncatingHead,  //非自动换行,行首切断 

NSLineBreakByTruncatingTail,  //非自动换行,行尾切断 

NSLineBreakByTruncatingMiddle  //非自动换行,中间切断  };

 // hyphenationFactor      连字符属性,取值 0 - 1

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,319评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,801评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,567评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,156评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,019评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,090评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,500评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,192评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,474评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,566评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,338评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,212评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,572评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,890评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,169评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,478评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,661评论 2 335

推荐阅读更多精彩内容

  • 与NSString类似,在iOS中AttributedString也分为NSAttributedString和 N...
    钱十六阅读 751评论 0 0
  • - (void)loadView { [super loadView]; //1.UILable的大小自适应实例:...
    一杯冰可乐阅读 9,002评论 0 7
  • 转载:http://blog.csdn.net/u010330109/article/details/518821...
    F麦子阅读 4,135评论 0 3
  • 明明已经相隔 十万八千里, 可我的心里 总觉得 还有一个你 和我在一起, 你在背后默默地 注视着我, 给我勇气, ...
    金赛月阅读 288评论 2 2
  • 感恩爸爸做的好饭菜 感恩妈妈的提醒 感恩宝宝给我带来快乐 感恩师父对我的教导 感恩同事的帮助 感恩朋友帮忙交话费 ...
    海清_3a07阅读 142评论 0 1