我需要在导航栏上设置最小字体比例。我在AppDelegate.m中设置标题属性:
[[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导航栏图像和文本属性,一切都可以正常工作,但如果可能,我需要设置最小字体比例。
最佳答案
我通过创建标签并用作导航栏标题来解决它。
// 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];