ios – 向leftBarButtonItem添加一个后退箭头?

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

有没有办法做到这一点?

解决方法

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

要隐藏后退按钮使用此:

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;

这对你有用.快乐的编码

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...