ios - How to use asset catalog for navigation bar background image? -
i use asset catalog 2x
images iphone5 , 6 described in docs:
image navigation bar background 750x128 (750 x 44 * 2 + 20 * 2) because want cover status bar. 750 iphone6 resolution width. bg image setting:
self.navigationcontroller?.navigationbar .setbackgroundimage(uiimage(named: "nav_bar_bg"), forbarmetrics: .default)
let's @ result:
ok. iphone5:
not ok. how can downscale without removing background image asset catalog? don't want hardcode it. it's annoying iphone5 , 6 resources can't separated.
any suggestions? thanks
sorry, didn't notice uinavigationbar thing... can change resize of picture used in background making picture stretchable. way can use picture fits smaller devices (the iphone5 in example) , keep picture centered in iphone 6.
another more convoluted solution subclass navbar altogether , rewrite way picture drawn.
you should use nslayoutconstraints (leading, top , trailing), , set uiimageview content fit. way won't need change image, automatically scaled application.
Comments
Post a Comment