如何大写标签的第一个字母

时间:2013-05-16 11:59:25

标签: iphone uilabel

这是我的代码: -

我需要只将Word的第一个字母更改为大写。

UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(10, 90, 200, 30)];
lbl4.text= [NSString stringWithFormat:@"(%@)", [arrtype  objectAtIndex:0]];
lbl4.font = [UIFont fontWithName:@"Helvetica" size:18];
lbl4.textColor=[UIColor blackColor];
lbl4.backgroundColor=[UIColor clearColor];

3 个答案:

答案 0 :(得分:3)

大写是字符串而不是标签

使用

[NSString capitalizedString]

将字符串大写并将其设置为标签

的文本
lbl4.text= [[NSString stringWithFormat:@"(%@)", [arrtype  objectAtIndex:0]]capitalizedString];

答案 1 :(得分:0)

使用此

UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(10, 90, 200, 30)];

NSString *abc = [NSString stringWithFormat:@"(%@)", [arrtype  objectAtIndex:0]];

abc = [NSString stringWithFormat:@"%@%@",[[abc substringToIndex:1] uppercaseString],[abc substringFromIndex:1]];

lbl4.text = abc;

lbl4.font = [UIFont fontWithName:@"Helvetica" size:18];

lbl4.textColor=[UIColor blackColor];

lbl4.backgroundColor=[UIColor clearColor];

答案 2 :(得分:0)

NSString *abc = @"demo";
abc = [NSString stringWithFormat:@"%@%@",[[abc substringToIndex:1] uppercaseString],[abc substringFromIndex:1] ];       
NSLog(@"abc = %@",abc);