I have a UITextView where the user can input text. Say the user has already inputted a value. How can I change the font color of that already typed text and future typed text to a different one with the click of a button?
I already have it set up where I can change the color of the text but it only works if I choose a color BEFORE I start typing. After I start typing and I attempt to change the color, it doesn't do anything.
I have this:
-(IBAction)changeInkColor:(id)sender { [inkTextField setTextColor:[UIColor greenColor]]; inkTextField.text=@"text"; }
and that actually works and displays "text" in green only if there is no text already in the view. However if I type something in and then hit this button, nothing happens.
Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.
Users can change the style of the element using the . style property. Also, we can change the specific style, such as element color, background color, size, etc. In our case, we will change the color attribute values to change the font color.
yes you can do it. [tFild_1 setFont:[UIFont fontWithName:@"Helvetica Neue" size:17]]; instead of "Helvetica Neue" use your font name.
I just tried that and I had no problems. I set up a button that called [myTextView setTextColor:[UIColor redColor]];
After typing a bit with black text color, I pressed the button, and everything turned red. Then I continued typing, all in red.
Are you using setTextColor:
to do this also?
In the end, setTextColor:
is the answer, there's an important detail missing from the earlier answers: To get this to work in iOS 8, I had to set the color =after= I set the text.
Hence,
- (void)viewDidLoad { [super viewDidLoad]; _myTextView.textColor = [UIColor whiteColor]; _myTextView.text = @"yadda yadda yadda..."; // etc., snip
Did NOT work, while
- (void)viewDidLoad { [super viewDidLoad]; _myTextView.text = @"yadda yadda yadda..."; _myTextView.textColor = [UIColor whiteColor]; // etc., snip
DID work. This strikes me as a bug in iOS 8, which I will write up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With