【问题标题】:iOS navigationItem.titleView remove marginsiOS navigationItem.titleView 移除边距
【发布时间】:2014-05-01 03:43:58
【问题描述】:

我有这样的事情:

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

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

@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,但得到了相同的结果。我在其他帖子中读到,可能是子类可以解决问题,但不知道如何实现该解决方案...

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

【问题讨论】:

标签: ios uiview uinavigationbar uinavigationitem titlebar


【解决方案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);

如果此建议对您没有帮助,那么在initWithFrameXHScrollMenu 下肯定有问题。进入这个方法并在那里检查。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 2022-01-05
    相关资源
    最近更新 更多