ios - Background image of opaque navigation bar is rendered incorrectly on iPhone 6 -
when set background image method
setbackgroundimage:forbarmetrics:
it's rendered on iphone 6
if set navigation bar translucent
, it's stretched normally.
@implementation ohcnavigationbar - (id)initwithcoder:(nscoder *)adecoder { if(self = [super initwithcoder:adecoder]) { [self setupgradient]; } return self; } - (instancetype)initwithframe:(cgrect)frame { if(self = [super initwithframe:frame]) { [self setupgradient]; } return self; } - (void)setupgradient { uiimage *gradientimage = [uiimage imagenamed:@"navigationbarbackground.png"]; [self setbackgroundimage:gradientimage forbarmetrics:uibarmetricsdefault]; } @end
you can set uinavigationbar
background image non repeat mode setting edge 0.
uiimage *gradientimage32 = [[uiimage imagenamed:@"bkg_top_header_default.png"] resizableimagewithcapinsets:uiedgeinsetsmake(0, 0, 0, 0)]; [[uinavigationbar appearance] setbackgroundimage:gradientimage32 forbarmetrics:uibarmetricsdefault]; [self.navigationcontroller.navigationbar setbackgroundimage:gradientimage32 forbarmetrics:uibarmetricsdefault];
update 1:
- (void)setupgradient { uiimage *gradientimage = [[uiimage imagenamed:@"navigationbarbackground.png"] resizableimagewithcapinsets:uiedgeinsetsmake(0, 0, 0, 0) resizingmode:uiimageresizingmodestretch]; [self setbackgroundimage:gradientimage forbarmetrics:uibarmetricsdefault]; }
may you.
enjoy coding !!