2012-12-18 163 views
0

我有一个左栏按钮项目。但我希望它能够更多地向右移动。此刻它粘在左手边。任何机构都有一个想法,我怎么能做到这一点?向左移动barbutton项目向右移动

这是我的按钮本身的代码。

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]; 

希望任何人能帮我这个。

亲切的问候

回答

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]; 
+0

为我工作!谢谢 – Steaphann

0

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

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