-3

i want to append two label texts(which are in different colors) in One label.any help please? how can i do it?

senthilM
  • 9,414
  • 18
  • 77
  • 140

2 Answers2

1

you can use one UILabel with two other UILabels with their own setups as a subviews. smth like this

UILabel* mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 120, 40)];
UILabel* firstSublabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
[firstSublabel setText:@"asd"];
[firstSublabel setTextColor:[UIColor redColor]];
[mainLabel addSubview:firstSublabel];
[firstSublabel release];
UILabel* secondSublabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, 60, 40)];
[secondSublabel setText:@"dfg"];
[secondSublabel setTextColor:[UIColor greenColor]];
[mainLabel addSubview:secondSublabel];
[secondSublabel release];
[self.view addSubview:mainLabel];
[mainLabel release];
Morion
  • 9,351
  • 1
  • 23
  • 33
0

Not really in a nice way.

There are some ideas for replacements in this question: Why is there no NSAttributedString on the iPhone?

Community
  • 1
  • 1
Georg Schölly
  • 120,563
  • 48
  • 208
  • 262