gpt4 book ai didi

ios - 更改后退导航栏按钮的字体

转载 作者:IT老高 更新时间:2023-10-28 11:36:49 25 4
gpt4 key购买 nike

我希望能够设置我的应用导航栏后退按钮的字体,而不会做任何过于疯狂的事情并且不会丢失按钮的任何其他设计特征(即我想保留箭头)。

现在我在 viewDidAppear: 中使用它来设置普通栏按钮项的字体。

for (NSObject *view in self.navigationController.navigationBar.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
[((UIButton*)view).titleLabel setFont:[UIFont
fontWithName:@"Gill Sans"
size:14.0]];
}
}

但是,无论此代码应用于哪个 UIViewController(根、当前等),这都不会改变后退按钮。

最佳答案

要更改所有 UINavigationBars 中出现的所有 UIBarButtonItems 中文本的外观,请在 application:didFinishLaunchingWithOptions:

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:
@{UITextAttributeTextColor:[UIColor blackColor],
UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
UITextAttributeTextShadowColor:[UIColor whiteColor],
UITextAttributeFont:[UIFont boldSystemFontOfSize:12.0]
}
forState:UIControlStateNormal];

更新:iOS7 友好版本

NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(0.0, 1.0);
shadow.shadowColor = [UIColor whiteColor];

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor blackColor],
NSShadowAttributeName:shadow,
NSFontAttributeName:[UIFont boldSystemFontOfSize:12.0]
}
forState:UIControlStateNormal];

swift :

注意:这会更改 UIBarButtonItem 的所有实例,而不仅仅是 UINavigationBar

中包含的那些实例
UIBarButtonItem.appearance()
.setTitleTextAttributes([NSFontAttributeName : ExamplesDefaults.fontWithSize(22)],
forState: UIControlState.Normal)

Swift3:

UIBarButtonItem.appearance()
.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "FontName-Regular", size: 14.0)!],
for: .normal)

关于ios - 更改后退导航栏按钮的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16535507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com