2

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.

Community
  • 1
  • 1
ChallengerGuy
  • 2,385
  • 6
  • 27
  • 43

4 Answers4

13

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.

Tolga Katas
  • 365
  • 1
  • 6
0

You are sure that your codeText variale is not nil? in my opinion your code should work. Please check wether codeText is not nil.

Robert
  • 3,790
  • 1
  • 27
  • 46
  • It is connected to my ViewController with an @IBOutlet. It's not nil and does show the text I've assigned from within the ViewController, just won't change the color. – ChallengerGuy Aug 13 '16 at 15:58
0

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.

ChallengerGuy
  • 2,385
  • 6
  • 27
  • 43
0

You need to add NSAttributedString with .foregroundColor: UIColor.label

  • It's nice to provide a visual aid; however, your answer should explain how to solve the question with out the need for the visual aid. Also, if you're going to provide code, please do so as text in the body of the answer. – Display name May 19 '20 at 15:06