Chr*_*ler 26 fonts title uinavigationcontroller ios
我可以更改我的UINavigationController的字体吗?- > 标题
mor*_*des 73
从iOS 5开始,您可以通过外观代理更改字体.
https://developer.apple.com/documentation/uikit/uiappearance
以下将为所有UINavigationControllers设置标题字体.
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"Didot" size:16] forKey:NSFontAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
Run Code Online (Sandbox Code Playgroud)
要设置后退按钮的字体,请执行以下操作:
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:@"Didot" size:12] forKey:NSFontAttributeName];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
要设置iOS 11+中可用的大型标题的字体,请执行以下操作:
if (@available(iOS 11.0, *)) {
NSMutableDictionary *largeTitleTextAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] largeTitleTextAttributes]];
[largeTitleTextAttributes setValue:[UIFont fontWithName:@"Didot" size:32] forKey:NSFontAttributeName];
[[UINavigationBar appearance] setLargeTitleTextAttributes:largeTitleTextAttributes];
}
Run Code Online (Sandbox Code Playgroud)
Mac*_*wia 24
对于iOS8 +,您可以使用:
[self.navigationController.navigationBar setTitleTextAttributes:@{ NSFontAttributeName: [UIFont fontWithName:@"MyFont" size:18.0f],
NSForegroundColorAttributeName: [UIColor whiteColor]
}];
Run Code Online (Sandbox Code Playgroud)
Jon*_*att 10
一个例子:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [FontHelper fontFor:FontTargetForNavigationHeadings];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = self.navigationItem.title;
// emboss in the same way as the native title
[label setShadowColor:[UIColor darkGrayColor]];
[label setShadowOffset:CGSizeMake(0, -0.5)];
self.navigationItem.titleView = label;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28832 次 |
| 最近记录: |