【问题标题】:Custom Navigation bar in iOSiOS中的自定义导航栏
【发布时间】:2015-08-12 01:28:53
【问题描述】:

是否可以在iOS导航栏下添加拖曳按钮,如下图所示:

如果是,请告诉我怎么做。

【问题讨论】:

  • 这是安卓截图。 iOS 和 Android 对此有不同的指导方针。在 iOS 上,您通常希望将 UISegmentedControl 作为导航项的标题视图。
  • 我猜,PetahChristian 已经为您指明了正确的方向。但是,我的建议是创建一个看起来像导航栏的自定义视图。
  • 如果答案有帮助,请花一点时间接受。否则,如果您需要更多帮助,请评论答案(或更新您的问题)! :)

标签: ios iphone uinavigationbar


【解决方案1】:

查看 Apple 的 Customizing UINavigationBar sample code 中的 ExtendedNavBar 示例。

【讨论】:

    【解决方案2】:

    实际上也可以这样做;但我不建议您这样做,因为这可能会破坏即将发布的 iOS 版本中的应用程序..

    如果你想这样做,请查看 Stackoverflow 上的帖子

    iPhone - How set uinavigationbar height?

    它将帮助您使导航栏更高。只需创建一个自定义 UINavigationBar 子类,它会覆盖 sizeThatFits: 并返回一个大尺寸。

    const CGFloat HeightToIncrease = 50.0f;
    
    @implementation MyNavigationBar
    
    - (CGSize)sizeThatFits:(CGSize)size {
    
        CGSize amendedSize = [super sizeThatFits:size];
        amendedSize.height += HeightToIncrease;
    
        return amendedSize;
    }
    
    @end
    

    您的视图看起来像 ![following][1]

    现在只需覆盖导航栏子类中的 layoutSubviews 并将按钮和标题向上移动以为按钮腾出空间

    喜欢关注

    - (void)layoutSubviews {
        [super layoutSubviews];     
    
        NSArray *classNamesToReposition = @[@"UINavigationItemView", @"UINavigationButton"];
    
        for (UIView *view in [self subviews]) {
    
            if ([classNamesToReposition containsObject:NSStringFromClass([view class])]) {
    
                CGRect frame = [view frame];
                frame.origin.y -= HeightToIncrease;
    
                [view setFrame:frame];
            }
        }
    }
    

    这将为您想要放置在导航中的按钮腾出空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      相关资源
      最近更新 更多