如何删除 UIBarButtonItem 旁边的填充 [英] How to remove padding next to a UIBarButtonItem
本文介绍了如何删除 UIBarButtonItem 旁边的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在导航栏的自定义右侧栏按钮项中添加了一个自定义按钮,如图所示.
I have added a custom button to the navigation bar's custom right bar button item as shown in the image.
我希望能够删除按钮后的空格,使其接触屏幕的右边缘,但即使在搜索后也找不到解决方案.如果有人能提到如何,那就太好了.
I'm want to be able to remove the space after the button so that it touches the right edge of the screen but couldn't find a solution even after searching. If someone could mention how, would be great.
这是我正在使用的代码
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(50.0, 0.0, 60, 44);
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(testButtonControl:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = aBarButtonItem;
推荐答案
您必须创建一个新视图,添加按钮和其他所有您想要的内容,并将其添加到 titleView,如图所示.
You have to create a new view, add button and everything else you want and add it to the titleView as shown.
- (void)viewDidLoad {
self.navigationItem.titleView = [self titleView];
}
- (UIView *)titleView {
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
CGFloat width = 0.95 * self.view.frame.size.width;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, navBarHeight)];
..
// please add what you need here
....
}
这篇关于如何删除 UIBarButtonItem 旁边的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文