我正在导航栏上添加两个自定义按钮,一个在左边,另一个在右边。我已经成功完成了它,但是我没有减少起始点和按钮框架之间的空间。
我尝试了很多次,也给出了负值的x,但仍然没有帮助。以下是按钮的代码:
我尝试了很多次,也给出了负值的x,但仍然没有帮助。以下是按钮的代码:
-(void)addLeftButton
{
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.backgroundColor = [UIColor redColor];
[aButton setTitle:@"H" forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, 40, 40);
[aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setLeftBarButtonItem:aBarButtonItem];
}
-(void)addRightButton
{
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.backgroundColor = [UIColor greenColor];
[aButton setTitle:@"B" forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, 40, 40);
[aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setRightBarButtonItem:aBarButtonItem];
}
也尝试使用了
aBarButtonItem.width = -16;
但并没有帮助。
如何实现这个呢...? 提前感谢...
这些是我喜欢的一些链接,但并没有什么帮助 如何编辑UINavigationBar中左右UIBarButtonItem的空白间隙 [iOS 7]
如何编辑UINavigationBar中左右UIBarButtonItem的空白间隙 [iOS 7]