Swift 可以使用以下代码为文本视图设置样式:
- 设置字体和字号:
textView.font = UIFont(name: "Helvetica", size: 14)
- 设置文本颜色:
textView.textColor = UIColor(red: 0.2, green: 0.3, blue: 0.4, alpha: 1.0)
- 设置文本的背景颜色:
textView.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0)
- 设置文本对齐方式:
textView.textAlignment = NSTextAlignment.center
- 设置行距:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10
textView.attributedText = NSAttributedString(string: "Hello World!", attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])