Jos*_*var 2 iphone xcode ios swift
我将背景图像放置为:
self.navigationController.navigationBar.setBackgroundImage(image, forBarMetrics: .Default)
Run Code Online (Sandbox Code Playgroud)
但是,重复图像。不,我希望它被重复给我并把它放在中心......?
以下是使用 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)
Run Code Online (Sandbox Code Playgroud)