gpt4 book ai didi

ios - 使 UIImage 填满整个导航栏

转载 作者:行者123 更新时间:2023-12-01 22:02:37 25 4
gpt4 key购买 nike

我想在 ui 导航栏中插入一个图像,并使它看起来像一个方面适合图像在 imageView 中的样子。
我正在这样做

navigationController?.navigationBar.compactAppearance?.backgroundImageContentMode = .scaleToFill
navigationController?.navigationBar.setBackgroundImage(image, for: .default)

但它给我的输出为:

enter image description here

我怎样才能使它完美。

最佳答案

使用 UIImageView 的最简单方法这里有 scaleAspectFit图像属性。尝试以下工作代码块。

func setNavigation() {
let imageView = UIImageView(image: UIImage(named: "bankselected"))
imageView.frame = navigationController!.navigationBar.frame
imageView.backgroundColor = .lightGray
imageView.contentMode = .scaleAspectFit
navigationController?.navigationBar.addSubview(imageView)
}

enter image description here

关于ios - 使 UIImage 填满整个导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60093879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com