自定义导航栏最小字体比例?

时间:2013-09-13 09:28:43

标签: ios xcode uinavigationbar customization title

我需要在导航栏上设置最小字体比例。我在AppDelegate.m中设置了title属性:

[[UINavigationBar appearance] setTitleTextAttributes: @{
                            UITextAttributeTextColor: [UIColor colorWithRed:54/255.0f green:54/255.0f blue:54/255.0f alpha:1.0f],
                     UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 0.0f)],
                                 UITextAttributeFont: [UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0f]
 }];

我的导航栏在我的故事板中的UIView上拖放。使用cusom导航栏图像和文本属性一切正常,但我需要设置最小字体比例。

1 个答案:

答案 0 :(得分:1)

我通过创建标签并将其用作导航栏标题来解决它。

// NavBar title
UILabel *customNavBarTitle = [[UILabel alloc] initWithFrame:CGRectMake(44, 0, 320, 44)];
customNavBarTitle.textAlignment = NSTextAlignmentCenter;
customNavBarTitle.adjustsFontSizeToFitWidth = YES;
[customNavBarTitle setFont:[UIFont fontWithName:@"OpenSans-Semibold" size:15.0f]];
[customNavBarTitle setBackgroundColor:[UIColor clearColor]];
[customNavBarTitle setTextColor:[UIColor blackColor];
[customNavBarTitle setText:customTitle];
[self.view addSubview:customNavBarTitle];
相关问题