如何在iphone中更改标题的字体大小?

时间:2011-08-18 07:16:07

标签: iphone objective-c ios xcode4

这是代码,这将显示默认大小,我想更改标题becoz的字体大小这个标题太大n没有显示整个只有“库克大印度......”正在显示...请允许我帮忙

- (void)viewDidLoad {

    self.title = @"Cook Great Indian Recipes";
}

2 个答案:

答案 0 :(得分:11)

尝试为标题标签设置自定义标签:

    self.title = @"Cook Great Indian Recipes";
    CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont boldSystemFontOfSize:20.0]].width, 44);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:17.0];
    label.textAlignment = UITextAlignmentCenter;
    self.navigationItem.titleView = label;
    label.text = self.title;
    [label release];

答案 1 :(得分:3)

您无法更改title的字体。而是使用您自己的自定义创建UILabel,并将其指定为 navigationItem的 titleView

UILabel *titleLbl = [[UILabel alloc] init];
label.frame = CGRectMake(...
label.font = [UIFont ...
// And the other things
self.navigationItem.titleView = titleLbl;
[titleLbl release];