tags:

views:

224

answers:

3

I really wonder if it possible to make some text in the same UILabel in diferent colour and diferent size ? if yes how ?

Please thank you so much for the further help.

A: 

Yeah look at this code:

- (IBAction) btnClickMe_Clicked:(id)sender {
    NSString *kw = s.text;

    NSString *encodedkw =  [kw stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *mms = [NSString stringWithFormat: @"%@", encodedkw];

    if ([mms length] == 0){
        iMessageLabel.text=@"put text";

    } else if ([mms isEqualToString:@"a"]){
        iMessageLabel.text=@"this is a";
    } else if ([mms isEqualToString:@"b"]){
        iMessageLabel.text=@"this is b";
    } else if ([mms isEqualToString:@"c"]){
        iMessageLabel.text=@"this is c";
    }else if ([mms isEqualToString:@"d"]){
        iMessageLabel.text=@"this is d";
    } else if ([mms isEqualToString:@"e"]){
        iMessageLabel.text=@"this is e";
    } else if ([ mms isEqualToString:@"f"]){
        iMessageLabel.text=@"this is f";
    }
}

this is my dictionary app(test app) and i want to make some special colour to the translated text and diferent size also for example.

-A verb this means A

I want tomake "verb" in the bold text. and this is A in the red colur.

I´m very new with this and really dont know if it possible to do like this, and if yes how you do ?

thanks so much

You a should add this as an edit to your original post. STO doesn't work like a forum thread. The question goes at the top and answers at the bottom. Each question and answer has its own comment thread.
TechZen
well, now i give up. and use UIwebview instead...easy and not get headach,,, :)Thanks for help :::::)))))
A: 

You change the text color like this:

myLabel.textColor=[UIColor blueColor];

You change font like:

myLabel.font= aFont; //a font object you've previously defined.

See UILabel Class Reference.

Edit01: Upon rereading, it appears the OP wants to change text attributes within the same string. In that case, you will need to use CFAttributedString. I haven't used it but I believe it works on the iPhone.

TechZen
so usefull answer actually :) thank you so much.but if i want it diferent colour in the same label if it possible ?I mean in one label have many clour of text, something like that :/
I believe that CFAttributedString will give you what you want. It lets you set text attributes like font and color on a character by character basis. It appears from the documentation that it does work on the iPhone whereas NSAttributedString does not.
TechZen
+1  A: 

iPhone doesn't have NSAttributedString, and it's pretty obvious that UILabel doesn't have a way to specify per-character attributes. So I think your only answer is to use WebKit (UIWebView).

David Dunham