[英]Change textColor of a UITextView in Swift
我有一个正在使用Xcode7
和Swift2
的iOS
项目。 我有一个UITextView
,我正在尝试更改它的textColor
。 它具有黑色背景色。
我在这里看,找不到setTextColor
。 我还在UITextView
所在的UIViewController
中尝试了以下方法,但没有成功:
@IBOutlet weak var codeText: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.codeText.delegate = self
codeText.textColor = UIColor.whiteColor()
}
然后我进入 Inspector 并尝试单击UITextView
并在那里更改textColor
但没有更改。 我做错了什么吗?
谢谢。
在您的 ViewController 上删除该行
self.codeText.delegate = self
您不能将“ViewController”类型的值分配给“UITextViewDelegate”类型吗?
codeText.textColor = UIColor.redColor()
工作得很好。
您确定您的 codeText 变量不为零吗? 在我看来,您的代码应该可以工作。 请检查 codeText 是否不为零。
我最终删除了Storyboard
的UITextField
并放置了一个新的。 我像以前一样使用@IBOutlet
将它连接到ViewController
。 然后我去了“产品”和“清洁”。 之后我运行了我的项目,它运行良好。 我仍然将新添加的名为codeText
UITextView
分配给UITextFieldDelegate
并且工作得很好。 一定只是有一个错误,需要重新开始。
你需要用 .foregroundColor: UIColor.label 添加 NSAttributedString
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.