简体   繁体   English

将左栏按钮项目向右移更多

[英]Move left barbutton item more to the right

I have a leftbar button item. 我有一个左键按钮项。 But I want it to move it more to the right. 但是我希望它向右移动。 At the moment it sticks to the left hand side. 此刻,它粘在左侧。 Any body has an idea how I can achieve this? 任何人都知道我该如何实现?

Here is my code for the button itself. 这是按钮本身的代码。

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

Hope anyone kan help me with this. 希望有人可以帮我这个忙。

Kind regards 亲切的问候

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

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

this is what I have done it worked for me 这就是我所做的对我有用的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM