2 bluetooth99 bluetooth99 于 2012.11.29 15:44 提问

RightBarButtonItem的问题

在NavigationBar 中有一个编辑按钮Edit Button,点击跳转“done”。把Edit和Done变为大写字母,有人知道怎么实现吗?谢谢

self.navigationItem.rightBarButtonItem = self.editButtonItem;

3个回答

abcdeFGh_xyz
abcdeFGh_xyz   2012.11.29 17:02
已采纳

.h文件中创建UIBarButtonItembtnEdit对象:

UIBarButtonItem *btnEdit;

.m中:

-(void)viewWillAppear:(BOOL)animated{
    btnEdit = [[UIBarButtonItem alloc]init];
    btnEdit.target = self;
    btnEdit.action = @selector(btnEdit_Click:);
    btnEdit.title = @"EDIT";
    self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnEdit;
    btnEdit.enabled=TRUE;
 }

-(IBAction)btnEdit_Click:(id)sender
{
    if ([btnEdit.title isEqualToString:@"EDIT"]) 
    {
        [btnEdit setTitle:@"DONE"]; 
    }
    else 
    {
        [btnEdit setTitle:@"EDIT"];   
    }
}
love_loveec
love_loveec   2012.11.29 17:26
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle: @"EDIT" style: UIBarButtonItemStyleBordered target: nil action: @selector(editPressed:self)];

[[self navigationItem] setRightBarButtonItem: newButton animated:NO];

newBackButton = nil;

然后:

-(void) editPressed: (id) sender
{
    ……
}
cai610182473
cai610182473   2014.02.27 17:53

self.navigationItem.leftBarButtonItem = self.editButtonItem;

点击显示Done,

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
navigationItem.rightBarButtonItem 设置背景图片,颜色更改解决办法
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"MoreImage"] style:UIBarButtonItemStylePlain target:self action:@selector(moreItemPress)];  
navigationItem左右按钮偏移的问题(left,right)
- (void)addBarButtonItemWithImageNameleftCustom:(NSString *)imageName selector:(SEL)selector close:(SEL)closeBtn {     UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];  
改变rightBarButtonItem字体的大小
改变rightBarButtonItem字体的大小     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(rightA
调整导航条上leftBarButtonItem和rightBarButtonItem与屏幕边界 或者与titleView 的间距
与屏幕边界 或者与titleView 的间距 只要分别调整rightBarButtonItems 数组元素的顺序。主要利用UIBarButtonItem 的UIBarButtonSystemItemFixedSpace 系统控件 UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
设置rightBarButtonItem图片不显示
//正确设置方法self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"big"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyl
ios UIBarButtonItem rightBarButtonItem Title 设置不了
// rightBarButtonItem Title 设置了不起作用,非要在alloc的时候就设置title才有效 UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"退出" style:UIBarButtonItemStyleBordered target:self action:@selec
调整导航条上leftBarButtonItem和rightBarButtonItem与屏幕边界的间距
我们发现,在设置navigationItem的leftBarButtonItem或rightBarButtonItem时,用CustomView初始化UIBarButtonItem,不论怎么设置CustomView的frame,添加到导航条上之后总是和屏幕边界有一定的间距(5pix),如何自由调整这个间距呢? 初始化一个用于控制间距的UIBarButtonItem实例negativeSp
rightBarButtonItem的title颜色修改
rightBarButtonItem的title颜色修改
给self.navigationItem.rightBarButtonItem设置字体颜色所引发的忧伤
其实一般去自定义一个 UIBarButtonItem 然后都会玩得很 high,很满足,但是孤独一生的我每次都是想法设法不去自定义,实在是 simple,但是毕竟也是好久没有搞iOS了,刚刚,想给 self.navigationItem.rightBarButtonItem 设置一下字体颜色: UIBarButtonItem *rightitem = [[UIBarButtonItem alloc
调整导航条上leftBarButtonItem和rightBarButtonItem与屏幕边界
我们发现,在设置navigationItem的leftBarButtonItem或rightBarButtonItem时,用CustomView初始化UIBarButtonItem,不论怎么设置CustomView的frame,添加到导航条上之后总是和屏幕边界有一定的间距(5pix),如何自由调整这个间距呢?         方法一:         考虑到CustomView一般