我将背景图片放在此处:
self.navigationController.navigationBar.setBackgroundImage(image, forBarMetrics: .Default)
但是,重复图像。不,我想让它重复给我并把它放在中心..?
答案 0 :(得分:4)
以下是使用UIAppearance和UIImage API修复它的方法:
// disable image stretching by defining left and top caps.
let navbarImage = image.stretchableImage(withLeftCapWidth: 1, topCapHeight: 1)
UINavigationBar.appearance().setBackgroundImage(navbarImage, for: .default)
答案 1 :(得分:0)
尝试使用适合我的method
以下。
var headerview = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
let imgview = UIImageView(frame: CGRect(x: 75, y: 0, width: 150, height: 44))
imgview.image = UIImage(named: "ImageName")
imgview.contentMode = UIViewContentMode.scaleAspectFit
headerview.addSubview(imgview)
self.navigationController?.navigationBar.topItem?.titleView = headerview