gpt4 book ai didi

ios - 设置导航栏背景图片

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

这是我的代码:

let logo = UIImage(named: "navigationbar")
self.navigationController!.navigationBar.setBackgroundImage(logo!.resizableImage(withCapInsets: UIEdgeInsets(top: 0,left: 0, bottom: 0 ,right: 0), resizingMode: .stretch), for: .default)

但不起作用。这是错误代码。

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

最佳答案

试试这段代码,看看你的代码在哪里崩溃了……它的起点……然后解决你的代码中 nil 的那部分……navigationControllerImage是零

if let logo = UIImage(named: "navigationbar") {
if let navigation = self.navigationController {

navigation.navigationBar.setBackgroundImage(logo!.resizableImage(withCapInsets: UIEdgeInsets(top: 0,left: 0, bottom: 0 ,right: 0), resizingMode: .stretch), for: .default)
}else {
print("Navigation cotroller not found and its nil")
}
} else {
print("problem wiyh image file")
}

关于ios - 设置导航栏背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61839084/

25 4 0