去掉 iOS 导航栏返回按钮文本三种计划
发布时间:2021-12-08 11:13:37 所属栏目:苹果资讯 来源:互联网
导读:鸿蒙官方战略合作共建HarmonyOS技术社区 自定义 UINavigationController 遵守 ``` 协议 实现下面方法: #pragma mark --------- UINavigationBarDelegate - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item {
|
鸿蒙官方战略合作共建——HarmonyOS技术社区 自定义 UINavigationController 遵守 ``` 协议 实现下面方法: #pragma mark --------- UINavigationBarDelegate ![]() - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { //设置导航栏返回按钮文字 UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:nil]; /* NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; textAttrs[UITextAttributeTextColor] = [UIColor whiteColor]; [back setTitleTextAttributes:textAttrs forState:UIControlStateNormal]; */ item.backBarButtonItem = back; return YES; } 注意:该方法会出现部分子控制器页面的返回按钮文字出现的bug,需要在其子控制器页面的父控制器里再次如上设置返回按钮才行 子控制器页面的父控制器 #pragma mark -------- 生命周期函数 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; //重新设置下级子页面导航栏返回按钮文字 UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = item; } 鸿蒙官方战略合作共建——HarmonyOS技术社区 自定义 UINavigationController 遵守 协议 实现下面方法: #pragma mark --------- UINavigationBarDelegate - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { //设置导航栏返回按钮文字为透明的,可能造成导航标题不居中的问题 [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted]; return YES; } 鸿蒙官方战略合作共建——HarmonyOS技术社区 给 UIViewController 添加类别(这里的类别不需要导入可直接使用) 然后在 load 方法里面用 Method Swzilling 方法替换交换 ViewDidAppear 方法,代码如下: #pragma mark --------- UINavigationBarDelegate - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { //设置导航栏返回按钮文字为透明的,可能造成导航标题不居中的问题 [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted]; return YES; } (编辑:52刷机网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

