简体   繁体   中英

How to change the font of UINavigation Controller Header.?

我想知道如何在使用UINavigationController的同时更改视图标题的字体大小..,提前谢谢

You can not directly change it. Create a custom UILabel , or any other view, with the style you want and assign it as self.navigationItem.titleView , instead.

    self.title = @"";
    UILabel *myNavigationTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, self.view.frame.size.width, 33)];
    myNavigationTitleLabel.textColor = [UIColor whiteColor];
    myNavigationTitleLabel.backgroundColor = [UIColor clearColor];
    myNavigationTitleLabel.text = @"my Custom title";
    myNavigationTitleLabel.textAlignment = UITextAlignmentCenter;
    myNavigationTitleLabel.font = [UIFont fontWithName:@"Arial" size:17];
    [self.navigationController.navigationBar addSubview:myNavigationTitleLabel];
    [myNavigationTitleLabel release];

Note that if you have landscape interface orientation you need to set new frame for the myNavigationTitleLabel.

change the font and title...

+(void) setNavigationTitle:(NSString *) title ForNavigationItem:(UINavigationItem *) navigationItem { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];

 UILabel *titleLbl = [[UILabel alloc] 

initWithFrame:CGRectMake(0.0f, 6.0f, 200.0f,30.0f)];

 [titleLbl setFont:[UIFont fontWithName:@"BellCent NamNum BT" 

size:24.0]];

 [titleLbl setBackgroundColor:[UIColor clearColor]]; [titleLbl setTextAlignment:UITextAlignmentCenter]; [titleLbl setTextColor:UIColorFromRedGreenBlue(35,134,192)]; [titleLbl setShadowColor:UIColorFromRedGreenBlue(186,186,186)]; [titleLbl setShadowOffset:CGSizeMake(1.0f, 1.0f)]; [titleLbl setText:title]; [view addSubview:titleLbl]; [navigationItem setTitleView:view]; [titleLbl release]; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM