-3

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

2 Answers2

0

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
  • 10,495
  • 1
  • 24
  • 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
  • 124,188
  • 49
  • 220
  • 267