UIViewController Title attribute in Storyboard

后端 未结 10 2126
南旧
南旧 2021-02-03 19:58

I am setting the title field of a UIViewController via Interface Builder/Storyboard: \"enter

10条回答
  •  情歌与酒
    2021-02-03 20:14

    Everything else on this page failed. For now, this worked, in code, in viewDidLoad:

    NSString* text = @"My page title";
    UIFont* font = [UIFont systemFontOfSize:20.0];
    const CGSize SIZE = [text sizeWithAttributes:@{NSFontAttributeName:font}];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SIZE.width, SIZE.height)];
    label.text = text;
    label.textColor = UIColor.blackColor;
    self.navigationItem.titleView = label;
    

提交回复
热议问题