I have an iOS
project I'm working on using Xcode7
and Swift2
. I have a UITextView
that I'm trying to change the textColor
of. It has a black background color.
I looked here and could not find a setTextColor
. I also tried below in the UIViewController
of where the UITextView
is located with no luck:
@IBOutlet weak var codeText: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.codeText.delegate = self
codeText.textColor = UIColor.whiteColor()
}
I then went into the Inspector and tried clicking on the UITextView
and changing the textColor
there with no luck of it changing. Am I doing something wrong?
Thank you.
on your ViewController remove the line
self.codeText.delegate = self
You can not assign a value of type "ViewController" to type "UITextViewDelegate?"
codeText.textColor = UIColor.redColor()
works just fine.
You are sure that your codeText variale is not nil? in my opinion your code should work. Please check wether codeText is not nil.
I ended up deleting the UITextField
in the Storyboard
and putting a new one. I connected it to the ViewController
with an @IBOutlet
as before. I then went to 'Product' and 'Clean'. Afterwards I ran my my project and it worked fine. I still had the newly added UITextView
called codeText
assigned to the UITextFieldDelegate
and works beautifully. Must have just had a bug in it and needed to start fresh.
你需要用 .foregroundColor: UIColor.label 添加 NSAttributedString
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.