0

I have a text view created dynamically no outlet ,I need to change the textview text colour.i have set dynamically the selectable "True",But the text is always showing in black colour don't know why. I have reached every where in google but not lucky to find the answer.

Ketan P
  • 4,259
  • 3
  • 30
  • 36
Ranjan Sahu
  • 300
  • 1
  • 2
  • 14

4 Answers4

0

Please set text color for each UITextView which you created dynamically :

SomeTextView.textColor = [UIColor redColor];

Hope This will help you !!!

Ketan P
  • 4,259
  • 3
  • 30
  • 36
0
UITextView *view = [[UITextView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)];
view.textColor = [UIColor redColor];
view.userInteractionEnabled = YES;
[self.view addSubview:view];
ios developer
  • 198
  • 19
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – HiDeoo Jul 13 '16 at 12:39
0
UITextView *txtView = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, 100, 100)];
txtView.textColor = [UIColor blueColor];
[self.view addSubview:txtView];

If u want to display the colour for particular words in textview u can try

NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:@"This is awesome"];

//Green color for the first four characters.

[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(0, 4)];

// Sets the font color of last four characters to yellow.

[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange(14, 10)];

You can achieve this by doing it programatically. Use NSMutableAttributedString

NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:@"This is awesome"];

//Green color for the first four characters.
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(0, 4)];

// Sets the font color of last four characters to yellow.
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange(14, 10)];

Set this text to your UITextView. It should work. Also make sure if text changes dynamically you need to care full with NSMakeRange.

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
remyr3my
  • 768
  • 1
  • 6
  • 19
0

Simplest way for changing textview text color is

UITextView *txtviewTextColor = [[UITextView alloc]init];
txtviewTextColor.frame = CGRectMake(10, 30, 200, 100);
txtviewTextColor.scrollEnabled = YES;
txtviewTextColor.textColor =[UIColor greenColor];
txtviewTextColor.userInteractionEnabled = YES;
[self.view addSubview:txtviewTextColor];
user3182143
  • 9,459
  • 3
  • 32
  • 39