今天做了一个自定义行间距的UITextView,用到了NSAttributedString类,于是就了解了下
,类NSMutableParagraphStyle可以用来自定义行间距
NSMutableParagraphStyle *tfStrinf = [[NSMutableParagraphStyle alloc] init];
tfStrinf.lineSpacing = 行间距;
用NSAttributedString定义文本,以下是关于其对应的键值的属性设置
NSFontAttributeName; //字体,value是UIFont对象NSParagraphStyleAttributeName;//绘图的风格(居中,换行模式,间距等诸多风格),value是NSParagraphStyle对象NSForegroundColorAttributeName;// 文字颜色,value是UIFont对象NSBackgroundColorAttributeName;// 背景色,value是UIFontNSLigatureAttributeName; // 字符连体,value是NSNumberNSKernAttributeName; // 字符间隔NSStrikethroughStyleAttributeName;//删除线,value是NSNumberNSUnderlineStyleAttributeName;//下划线,value是NSNumberNSStrokeColorAttributeName; //描绘边颜色,value是UIColorNSStrokeWidthAttributeName; //描边宽度,value是NSNumberNSShadowAttributeName; //阴影,value是NSShadow对象NSTextEffectAttributeName; //文字效果,value是NSStringNSAttachmentAttributeName;//附属,value是NSTextAttachment 对象NSLinkAttributeName;//链接,value是NSURL or NSStringNSBaselineOffsetAttributeName;//基础偏移量,value是NSNumber对象NSUnderlineColorAttributeName;//下划线颜色,value是UIColor对象NSStrikethroughColorAttributeName;//删除线颜色,value是UIColorNSObliquenessAttributeName; //字体倾斜NSExpansionAttributeName; //字体扁平化NSVerticalGlyphFormAttributeName;//垂直或者水平,value是 NSNumber,0表示水平,1垂直
这几个是用字典作为载体的
````NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13],
NSParagraphStyleAttributeName:tfStrinf,
NSForegroundColorAttributeName:[UIColor lightGrayColor]
};
NSAttributedString * atri = [[NSAttributedString alloc]initWithString:@"内容" attributes:attributes];
得到内容高度
CGRect rect = [atri boundingRectWithSize:CGSizeMake(MAINSCREEN.size.width-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];````
CGFloat tvH = rect.size.height;</br>_showTF.attributedText = atri;</br>之后在网上找到一个关于NSMutableParagraphStyle这个的详细解释blog.csdn.net/hello_hwc </br>http://blog.csdn.net/column/details/huangwenchen-ios-sdk.html
关于自定义行间距的UITextView
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...