iOS navigationItem.titleView删除边距

时间:2014-05-01 03:43:58

标签: ios uiview uinavigationbar uinavigationitem titlebar

我有这样的事情:

titleBar_image

但我需要为titleView设置的视图,左边和右边没有这些边距。像这样:

titleBar_image2

这就是我实际在做的事情:

@property (nonatomic, strong) XHScrollMenu *scrollMenu; // where XHScrollMenu is a subclass of UIView

- (void)viewdidLoad{
 _scrollMenu = [[XHScrollMenu alloc] initWithFrame:self.navigationController.navigationBar.frame];
 _scrollMenu.backgroundColor = [UIColor clearColor];
 _scrollMenu.delegate = self;
 _scrollMenu.selectedIndex = 0;
 self.navigationItem.titleView =self.scrollMenu;
}

我尝试给视图a使用320,但我得到了相同的结果。我在其他帖子中读到,也许一个子类可以解决问题,但不知道如何实现该解决方案...

如何使标题视图使用整个宽度?

1 个答案:

答案 0 :(得分:-1)

尝试使用bounds代替frame。见different between bounds and frame.

...initWithFrame:self.navigationController.navigationBar.bounds] /// or give frame manually such like CGRectMake(x,y,self.view.frame.size.width, yourHeight);

如果此建议无法帮助您,请确定initWithFrame XHScrollMenu下的问题。进入这个方法并检查那里。