Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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 在Swift中更改UITextView的文本颜色_Ios_Swift2_Uitextview_Textcolor - Fatal编程技术网

Ios 在Swift中更改UITextView的文本颜色

Ios 在Swift中更改UITextView的文本颜色,ios,swift2,uitextview,textcolor,Ios,Swift2,Uitextview,Textcolor,我有一个iOS项目,我正在使用Xcode7和Swift2。我有一个UITextView,我正试图更改它的textColor。它有一个黑色的背景色 我看了看,找不到setTextColor。我还在UITextView所在的UIViewController中尝试了以下内容,但没有成功: @IBOutlet weak var codeText: UITextView! override func viewDidLoad() { super.viewDidLoad() self.cod

我有一个
iOS
项目,我正在使用
Xcode7
Swift2
。我有一个
UITextView
,我正试图更改它的
textColor
。它有一个黑色的背景色

我看了看,找不到
setTextColor
。我还在
UITextView
所在的
UIViewController
中尝试了以下内容,但没有成功:

@IBOutlet weak var codeText: UITextView!
override func viewDidLoad() {
    super.viewDidLoad()

    self.codeText.delegate = self

    codeText.textColor = UIColor.whiteColor()
}
然后,我进入检查器,尝试单击
UITextView
并在那里更改
textColor
,但运气不佳。我做错什么了吗


谢谢。

您确定您的codeText变量不是零吗?在我看来,您的代码应该可以工作。请检查codeText是否为非零。

在您的ViewController上删除该行

self.codeText.delegate = self
不能将“ViewController”类型的值分配给“UITextViewDelegate”类型


工作正常。

我最终删除了
故事板中的
UITextField
,并放置了一个新的。我像以前一样用
@IBOutlet
将它连接到
ViewController
。然后我去了“产品”和“清洁”。后来我运行了我的项目,它工作得很好。我仍然将新添加的名为
codeText
UITextView
分配给
UITextFieldDelegate
,效果非常好。必须有一个bug,需要重新开始。

您需要添加带有.foregroundColor:UIColor.label的NSAttributed字符串。

它通过@IBOutlet连接到我的ViewController。它不是零,并且确实显示了我在ViewController中指定的文本,只是不会更改颜色。codeText的类型为
UITextView
,可以指定给代理。提供视觉辅助很好;但是,您的答案应该解释如何在不需要视觉辅助的情况下解决问题。另外,如果你要提供代码,请在答案正文中以文本形式提供。
codeText.textColor = UIColor.redColor()