带有外部字体的导航标题 'FuturaStd-Book'
Navigation Title Chopped with external Font 'FuturaStd-Book'
使用外部字体在导航中截断的标题 'FuturaStd-Book'。
尝试使用以下代码减小字体大小,但标题仍然被截断。
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:16]}];
请帮我解决这个问题...
您必须使用 navigationItem
的 titleView
。在您的 VC:
中试试这个
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
headerLabel.textAlignment = NSTextAlignmentCenter;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.text = @"Register";
headerLabel.font = [UIFont fontWithName:@"FuturaStd-Book" size:16];
headerLabel.textColor = [UIColor blackColor];
self.navigationItem.titleView = headerLabel;
输出:
以下代码对齐 navigationItem
标题。 (仅适用于 iOS 11 - 但向后导航和标题 y 位置不同)
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;
style.firstLineHeadIndent = 1.0f;
style.lineSpacing = 2; //Change spacing between lines
style.paragraphSpacing = 2; //Change space between paragraphs
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor],
NSBackgroundColorAttributeName:[UIColor clearColor],
NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:18],
NSParagraphStyleAttributeName: style }];
使用外部字体在导航中截断的标题 'FuturaStd-Book'。
尝试使用以下代码减小字体大小,但标题仍然被截断。
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:16]}];
请帮我解决这个问题...
您必须使用 navigationItem
的 titleView
。在您的 VC:
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
headerLabel.textAlignment = NSTextAlignmentCenter;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.text = @"Register";
headerLabel.font = [UIFont fontWithName:@"FuturaStd-Book" size:16];
headerLabel.textColor = [UIColor blackColor];
self.navigationItem.titleView = headerLabel;
输出:
以下代码对齐 navigationItem
标题。 (仅适用于 iOS 11 - 但向后导航和标题 y 位置不同)
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;
style.firstLineHeadIndent = 1.0f;
style.lineSpacing = 2; //Change spacing between lines
style.paragraphSpacing = 2; //Change space between paragraphs
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor],
NSBackgroundColorAttributeName:[UIColor clearColor],
NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:18],
NSParagraphStyleAttributeName: style }];