Lab、TextView文字两端对齐(中英文、标点、空格换行)
2017-04-10 17:11
453 查看
网上找了半天大部分都有各种各样的毛病。。话不多说,先看效果
代码附上:
/***********
-(NSAttributedString *)setTextString:(NSString *)text{
NSMutableAttributedString *mAbStr = [[NSMutableAttributedStringalloc]initWithString:text];
NSMutableParagraphStyle *npgStyle = [[NSMutableParagraphStylealloc]init];
npgStyle.alignment =NSTextAlignmentJustified;
npgStyle.paragraphSpacing =11.0;
npgStyle.paragraphSpacingBefore =10.0;
npgStyle.firstLineHeadIndent =0.0;
npgStyle.headIndent =0.0;
NSDictionary *dic =
@{
NSForegroundColorAttributeName:[UIColorcolorWithHexString:@"6a3906"],
NSFontAttributeName:[UIFontsystemFontOfSize:15.0],
NSParagraphStyleAttributeName :npgStyle,
NSUnderlineStyleAttributeName :[NSNumbernumberWithInteger:NSUnderlineStyleNone]
};
[mAbStrsetAttributes:dicrange:NSMakeRange(0,
mAbStr.length)];
NSAttributedString *attrString = [mAbStrcopy];
return attrString;
}
*/////////////
引用直接
/*****
text.attributedText = [selfsetTextString:String];
*//////
代码附上:
/***********
-(NSAttributedString *)setTextString:(NSString *)text{
NSMutableAttributedString *mAbStr = [[NSMutableAttributedStringalloc]initWithString:text];
NSMutableParagraphStyle *npgStyle = [[NSMutableParagraphStylealloc]init];
npgStyle.alignment =NSTextAlignmentJustified;
npgStyle.paragraphSpacing =11.0;
npgStyle.paragraphSpacingBefore =10.0;
npgStyle.firstLineHeadIndent =0.0;
npgStyle.headIndent =0.0;
NSDictionary *dic =
@{
NSForegroundColorAttributeName:[UIColorcolorWithHexString:@"6a3906"],
NSFontAttributeName:[UIFontsystemFontOfSize:15.0],
NSParagraphStyleAttributeName :npgStyle,
NSUnderlineStyleAttributeName :[NSNumbernumberWithInteger:NSUnderlineStyleNone]
};
[mAbStrsetAttributes:dicrange:NSMakeRange(0,
mAbStr.length)];
NSAttributedString *attrString = [mAbStrcopy];
return attrString;
}
*/////////////
引用直接
/*****
text.attributedText = [selfsetTextString:String];
*//////
相关文章推荐
- Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来
- Android TextView内容包含中英文时满行居中,不足一行则左对齐,会出现左右空格不一致。
- textview 文字排版问题,实现两端对齐
- textview文字对齐换行问题
- 实现TextView 文字排版,分散两端对齐
- Android textview文字对齐换行问题
- 自定义TextView使上下文字两端对齐
- 浅谈Android textview文字对齐换行的问题
- Android 自定义Textview实现文字两端对齐功能和长按自由选择文字弹出自定义ActionMenu功能(二)自定义ActionMenu
- android --- 空格占位符 与 TextView实现分散对齐(两端对齐)
- 实现TextView 文字排版,分散两端对齐
- TextView设置文字包含中英文时自动换行问题的终极解决方案
- Android TextView设置两端对齐,不区分中英文
- Android textview文字两端对齐,中间空白
- 自定义View--文字两端能够对齐的TextView,文字右端能够对齐的TextView
- Android 自定义Textview实现文字两端对齐功能和长按自由选择文字弹出自定义ActionMenu功能(一)
- JustifyTextView 解决TextView中英文混排自动换行的问题
- Android中用webView来解决文字排版实现两端分散对齐的方式
- [Android]TextView实现分散对齐(两端对齐)
- [Android]TextView实现分散对齐(两端对齐)