iPhone - How set uinavigationbar height?

后端 未结 9 2185
情歌与酒
情歌与酒 2020-11-28 05:25

I want to make the top of the navigation view a bit smaller. How would you achieve this? This is what I\'ve tried so far, but as you can see, even though I make the navigati

相关标签:
9条回答
  • 2020-11-28 06:19

    I have found the following code to perform better on iPad (and iPhone):

    - (CGSize)sizeThatFits:(CGSize)size
    {
         return CGSizeMake(self.superview.bounds.size.width, 62.0f);
    }
    
    0 讨论(0)
  • 2020-11-28 06:22

    Using this navigation bar subclass I've successfully created a larger navigation bar on iOS 5.x to iOS 6.x on the iPad. This gives me a larger navigation bar but doesn't break all the animations.

    static CGFloat const CustomNavigationBarHeight = 62;
    static CGFloat const NavigationBarHeight = 44;
    static CGFloat const CustomNavigationBarHeightDelta = CustomNavigationBarHeight - NavigationBarHeight;
    
    @implementation HINavigationBar
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
    //      UIColor *titleColor = [[HITheme currentTheme] fontColorForLabelForLocation:HIThemeLabelNavigationTitle];
    //      UIFont *titleFont = [[HITheme currentTheme] fontForLabelForLocation:HIThemeLabelNavigationTitle];
    
    //      [self setTitleTextAttributes:@{ UITextAttributeFont : titleFont, UITextAttributeTextColor : titleColor }];
    
            CGAffineTransform translate = CGAffineTransformMakeTranslation(0, -CustomNavigationBarHeightDelta / 2.0);
            self.transform = translate;
            [self resetBackgroundImageFrame];
    
        }
        return self;
    }
    
    - (void)resetBackgroundImageFrame
    {
        for (UIView *view in self.subviews) {
            if ([NSStringFromClass([view class]) rangeOfString:@"BarBackground"].length != 0) {
                view.frame = CGRectMake(0, CustomNavigationBarHeightDelta / 2.0, self.bounds.size.width, self.bounds.size.height);
            }
        }
    }
    
    - (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics
    {
        [super setBackgroundImage:backgroundImage forBarMetrics:barMetrics];
        [self resetBackgroundImageFrame];
    }
    
    - (CGSize)sizeThatFits:(CGSize)size
    {
        size.width = self.frame.size.width;
        size.height = CustomNavigationBarHeight;
        return size;
    }
    
    - (void)setFrame:(CGRect)frame
    {
        [super setFrame:frame];
        [self resetBackgroundImageFrame];
    }
    
    
    
    @end
    
    0 讨论(0)
  • 2020-11-28 06:22

    For swift

    create a subclass of Uinavigation bar.

    import UIKit
    
    class higherNavBar: UINavigationBar {
    
    override func sizeThatFits(size: CGSize) -> CGSize {
        var newSize:CGSize = CGSizeMake(self.frame.size.width, 87)
        return newSize
    }
    

    There will be two blank strips on both sides, I changed the width to the exact number to make it work.

    However the title and back button are aligned to the bottom.

    0 讨论(0)
提交回复
热议问题