【问题标题】:Modified navigationbar causes issues on button item修改后的导航栏导致按钮项目出现问题
【发布时间】:2015-11-27 17:02:41
【问题描述】:

在我们的项目中,我们想要更改导航栏的大小。用

实现了
@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
    return CGSizeMake(self.superview.bounds.size.width, 55.0f);
}
@end

但这里的问题是.. 正如您所见,go 按钮离屏幕边缘有点低。但我希望它位于屏幕的最终角落。我使用backgroundColor:setTitle:forState:methods 来构建go 按钮的外观。也返回按钮垂直居中。我怎样才能做到这一点。尝试使用 edgeInsets: 但没有希望。

编辑:Go 按钮高度比 barheight 小 10px。

如果我给出相同的高度。下面是结果

【问题讨论】:

  • 你增加按钮的高度了吗?
  • 按钮大小现在比条形高度小 10 px。如果我让它等于进入空白区域的 Go 按钮颜色的 5px
  • 等我试试这个。
  • @user3182143 检查我的编辑
  • 您是否以编程方式设置了设置按钮和高度?

标签: ios objective-c


【解决方案1】:

在某种程度上我已经尝试过你的编码。检查一下

UIButton *goBtn = [UIButton buttonWithType:UIButtonTypeCustom];
goBtn.frame = CGRectMake(0, 0, 63, 80);
goBtn.backgroundColor = [UIColor redColor];
UIView *goButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 63, 50)];
NSLog(@"goButtonView bounds are - %@", NSStringFromCGRect([goButtonView bounds]));
goButtonView.bounds = CGRectOffset(goButtonView.bounds, -17, 0);
NSLog(@"goButtonView bounds are - %@", NSStringFromCGRect([goButtonView bounds]));
[goButtonView addSubview:goBtn];
UIBarButtonItem *goButton = [[UIBarButtonItem alloc] initWithCustomView:goButtonView];
self.navigationItem.rightBarButtonItem = goButton;

参考文献下方

Issue with button on the left side of the uinavigation bar

UINavigationBar UIBarButtonItems much larger click area than required

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多