【发布时间】:2018-07-15 15:41:49
【问题描述】:
我正在尝试构建一个分配给我的故事板中的导航控制器的 Cocoa Touch 类,以在中心的导航栏中显示图像。应用程序构建,但图像未显示,我可以找出原因。
我正在尝试构建一个分配给我的故事板中的导航控制器的 Cocoa Touch 类,以在中心的导航栏中显示图像。应用程序构建,但图像未显示,我可以找出原因。
class NavBarImg: UINavigationController {
required init(coder aDecoder: NSCoder){
super.init(coder: aDecoder)!
setupView()
}
func setupView()
{
if navigationController == nil{
return
}
let image = #imageLiteral(resourceName: "BarTabsNavLogoWhite")
let imageView = UIImageView(image: image)
let bannerWidth = navigationBar.frame.size.width
let bannerHeight = navigationBar.frame.size.height
let bannerX = bannerWidth / 2 - image.size.width / 2
let bannerY = bannerHeight / 2 - image.size.height / 2
imageView.frame = CGRect(x: bannerX, y: bannerY, width: bannerWidth, height: bannerHeight)
imageView.contentMode = .scaleAspectFit
self.navigationItem.titleView = imageView
}
}
【问题讨论】:
-
这段代码是在setupView还是在哪里???
-
你的图片尺寸是多少?
标签: ios swift cocoa-touch uinavigationcontroller