向leftBarButtonItem添加一个后退箭头? [英] Add a back arrow to leftBarButtonItem?

查看:103
本文介绍了向leftBarButtonItem添加一个后退箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 leftBarButtonItem 中添加一个向后箭头,使其看起来像是一个常规的后退按钮,虽然它的功能略有不同。

I want to add a back arrow to a leftBarButtonItem, to make it appear visually as if it was a regular back button, although it's functionality is slightly different.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

你可以使用自定义如果您使用导航控制器,则按钮并隐藏后退按钮。

You can use custom button and hide the back button if you are using navigation controller.

要隐藏后退按钮,请使用此按钮:

To hide back button use this:

self.navigationItem.hidesBackButton = YES;

自定义按钮:

UIButton * customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setBackgroundColor:[UIColor colorWithRed:197.0/255.0 green:190.0/255.0 blue:157.0/255.0 alpha:1.0]];
[customButton setTitle:@"Do Something" forState:UIControlStateNormal];
customButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:11.0f];
[customButton.layer setCornerRadius:3.0f];
[customButton.layer setMasksToBounds:YES];
[customButton.layer setBorderWidth:1.0f];
[customButton.layer setBorderColor: [[UIColor grayColor] CGColor]];
customButton.frame=CGRectMake(0.0, 100.0, 50.0, 25.0);
[customButton addTarget:self action:@selector(customMethod:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * customItem = [[UIBarButtonItem alloc] initWithCustomView:customButton];
customItem.tintColor=[UIColor blackColor];
self.navigationItem.leftBarButtonItem = customItem;

这对你有用。
快乐编码

这篇关于向leftBarButtonItem添加一个后退箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆