向左移动左侧栏按钮项目

时间:2012-12-18 07:54:31

标签: iphone objective-c ios uinavigationcontroller

我有一个左键按钮项。但是我希望它能够向右移动它。此刻它粘在左手边。任何机构都知道如何实现这个目标?

这是按钮本身的代码。

 UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"task_status.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(changeStatus:) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(80, 0,100, 18)];
    self.tabBarController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

希望有人能帮助我。

亲切的问候

2 个答案:

答案 0 :(得分:0)

为什么不直接添加右键按钮?

self.tabBarController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(changeStatus:)] autorelease];

答案 1 :(得分:0)

这就是我为我所做的工作

UIImage *image = [UIImage imageNamed:@"btn_bar_back.png"] ;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10.0, -15.0, image.size.width, image.size.height);//set your button frame
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitle:@"BACK" forState:UIControlStateNormal];
button.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);// if want to move text more towards right
[button addTarget:self action:@selector(backButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width+10, 50)];
button.center = CGPointMake(view.center.x, view.center.y);
[view addSubview:button];

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:view] autorelease];

[view release];