android中怎么调整字体的间距和行间距
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android中怎么调整字体的间距和行间距相关的知识,希望对你有一定的参考价值。
可以设置属性android:lineSpacingExtra或android:lineSpacingMultiplier。关于Android下TextView中文换行问题,可查看Android自定义view-文本自动换行。
1、android:lineSpacingExtra
设置行间距,如”3dp”。
2、android:lineSpacingMultiplier
设置行间距的倍数,如”1.2″。 参考技术A e no mistake about this assembly, no chasing im
调整label的行间距、字间距
参考技术A //改变label的行间距- (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:label.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:space];
[attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [label.text length])];
label.attributedText = attributedStr;
[label sizeToFit];
//改变label的字间距
- (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@NSKernAttributeName:@(space)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [label.text length])];
label.attributedText = attributedString;
[label sizeToFit];
//改变行间距和字间距
- (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@NSKernAttributeName:@(wordSpace)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpace];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [label.text length])];
label.attributedText = attributedString;
[label sizeToFit];
以上是关于android中怎么调整字体的间距和行间距的主要内容,如果未能解决你的问题,请参考以下文章