iphone UITextView设置行间距 [英] iphone UITextView set line spacing

查看:383
本文介绍了iphone UITextView设置行间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在UITextView中增加行空间,使其在iPhone中看起来像Notes应用程序?

How can I increase line space in UITextView so that it looks like "Notes" app in iPhone?

推荐答案

现在好了在iOS6上,有一种可能性,使用NSParagraphStyle,但它的记录很少,似乎很少工作。

Well now on iOS6, there is a possibility, using NSParagraphStyle, but it is very poorly documented and seems to work seldomly.

我目前正在解决这个问题:

im currently working about it like this:

UITextView *lab = [LocalTexts objectAtIndex:j];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineHeightMultiple = 50.0f;
paragraphStyle.maximumLineHeight = 50.0f;
paragraphStyle.minimumLineHeight = 50.0f;

NSString *string = lab.text;
NSDictionary *ats = @{
NSFontAttributeName : [UIFont fontWithName:@"DIN Medium" size:16.0f],
NSParagraphStyleAttributeName : paragraphStyle, 
};

lab.attributedText = [[NSAttributedString alloc] initWithString:string attributes:ats];

问题是当你设置字体时,行高停止工作..非常奇怪,避风港' t找到了它的修复程序。

Problem is that when you set the font, the line height stops working.. very odd, haven't found a fix for it yet.

你也可以创建一个自定义的Attributed CoreText视图......但它的技术性更强一点,你可以找到它的演示方法已完成此处

Also you can create a custom Attributed CoreText view... but its a bit more technical, you can find a demo of how it is done here

我希望有所帮助。

这篇关于iphone UITextView设置行间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆