Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 调整UITextView的行距_Ios_Swift_Uitextview - Fatal编程技术网

Ios 调整UITextView的行距

Ios 调整UITextView的行距,ios,swift,uitextview,Ios,Swift,Uitextview,如何调整UITextView的行高度(行距)?在哪里更改/添加代码?我目前正在尝试向AppDelegate.swift文件中的didfishlaunchwithoptions函数添加代码。这是我的密码: func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { // Override point for

如何调整UITextView的行高度(行距)?在哪里更改/添加代码?我目前正在尝试向AppDelegate.swift文件中的
didfishlaunchwithoptions
函数添加代码。这是我的密码:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions:     NSDictionary!) -> Bool {
    // Override point for customization after application launch.
    var paragraphStyle = NSMutableParagraphStyle()
    return true
}
然后选择UITextView并添加以下用户定义的运行时属性:

paragraphStyle.lineSpacing = 40

我已经知道我这样做是完全错误的;我怎样才能把它做好呢?

您只是在创建一个空段落样式。只有应用程序代理知道这一点

相反,您应该在管理
UITextView
的类中设置文本样式(没有
UITextLabel
)。获取对文本视图的引用后,可以执行以下操作:

let style = NSMutableParagraphStyle()
style.lineSpacing = 40
let attributes = [NSParagraphStyleAttributeName : style]
textView.attributedText = NSAttributedString(string: yourText, attributes:attributes)

您还可以仅将样式应用于文本的指定部分(
NSRange
)。但这稍微复杂一点,所以您应该在这里问另一个问题。

我如何“获取对我的文本视图的引用”/“在管理UITextView的类中设置我的文本样式?”(我是这方面的新手-thx)