【问题标题】:Position UIBarButtonItem on edge of UINavigationBar将 UIBarButtonItem 定位在 UINavigationBar 的边缘
【发布时间】:2012-06-10 14:42:59
【问题描述】:

是否可以在 UINavigationBar 的左侧或右侧 边缘 放置自定义图像 UIBarButton 项?如果按钮的边缘接触 UINavigationBar 的边缘,我创建按钮的方式看起来最好。

【问题讨论】:

  • 为什么不可能?您是使用 Interface Builder 还是以编程方式创建视图?
  • 实际使用情节提要。我宁愿通过故事板创造一切。基本上,我只想轻松删除右侧 UIBarButton 右侧的填充和左侧 UIBarButtonItem 左侧的填充。

标签: uinavigationbar uibarbuttonitem


【解决方案1】:

您最好的选择是继承 UINavigation 栏并覆盖布局子视图。

在我的示例中,如果按钮的标签为 900,我将其移动到最左边缘。

- (void) layoutSubviews {
    [super layoutSubviews];
    //override the navigation bar to move classes with 900 to the ledge
    for (UIView *view in self.subviews) {  
        if ([view isKindOfClass:[UIButton class]]) {  
            if (view.tag == 900)
                view.frame = CGRectMake(0,0, 88, 44);
        }

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    相关资源
    最近更新 更多