ios零基础学习吧 关注:1贴子:23
  • 0回复贴,共1

设置UITextView的字符间距

只看楼主收藏回复

在iOS7中有两种方法:
1. 通过设置attributedString来设置。
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];paragraphStyle.headIndent = 15; // <--- indention if you need itparagraphStyle.firstLineHeadIndent = 15;paragraphStyle.lineSpacing = 7; // <--- magic line spacing here!NSDictionary *attrsDictionary =@{ NSFontAttributeName: font, <-- if you need; & there are many more attrs NSParagraphStyleAttributeName: paragraphStyle};self.textView.attributedText = [[NSAttributedString alloc] initWithString:@"Hello World over many lines!" attributes:attrsDictionary];
2. 设置属性layoutManager.delegate来实现:
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect{ return 20; // For really wide spacing; pick your own value}
转自:http://www.ihugo.xyz


IP属地:加拿大1楼2015-05-27 10:44回复