办法1
// MARK: - 获得一个拉伸的图片 extension UIImage{ func getTensileImage() -> UIImage{ let leftCapWidthUnderView = self.size.width * 0.5; let topCapHeightUnderView = self.size.height * 0.5 return self.stretchableImage(withLeftCapWidth: Int(leftCapWidthUnderView), topCapHeight: Int(topCapHeightUnderView)) } }
使用
self.bgView.image = UIImage.init(named: model["bgView"] ?? "")?.getTensileImage()
办法2
/*
* Stretch 拉伸
* Tile 平铺
*/
self.bgView.image = UIImage.init(named: model["bgView"] ?? "")?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 40), resizingMode: UIImageResizingMode.stretch)
转自:https://blog.csdn.net/wc455287693/article/details/47294547