我想向leftBarButtonItem
添加后退箭头,以使其看起来像是常规的后退按钮,尽管它的功能略有不同。
有没有办法做到这一点?
最佳答案
如果使用导航 Controller ,则可以使用自定义按钮并隐藏后退按钮。
要隐藏后退按钮,请使用以下命令:
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;
这将为您工作。
快乐编码