导航项 Swift 3 到 Swift 4
Navigation Item Swift 3 to Swift 4
我一直遇到的问题是,在我下载 Xcode 9 之后,我的应用程序的用户界面变得一团糟。
let item1 = UIBarButtonItem(image: #imageLiteral(resourceName: "SettingsInto"), style: .done, target: self, action: #selector(settingsPressed))
self.navigationItem.setRightBarButton(item1, animated: true)
let item2 = UIBarButtonItem(image: #imageLiteral(resourceName: "search icon"), style: .plain, target: self, action: #selector(searchPressed))
self.navigationItem.setLeftBarButtonItem(item2, animated: true)
let imageButton = UIButton(frame: CGRect(x: 0, y: 0, width: 0, height: navigationBarHeight))
let image = #imageLiteral(resourceName: "Stickiie Logo Main")
imageButton.setImage(image, for: UIControlState())
imageButton.imageView?.contentMode = .scaleAspectFit
imageButton.addTarget(self, action: #selector(refresh), for: .touchDown)
self.navigationItem.titleView? = imageButton
在 Xcode 9 之前:
Xcode9 之后:
我一直遇到的问题是,在我下载 Xcode 9 之后,我的应用程序的用户界面变得一团糟。
let item1 = UIBarButtonItem(image: #imageLiteral(resourceName: "SettingsInto"), style: .done, target: self, action: #selector(settingsPressed))
self.navigationItem.setRightBarButton(item1, animated: true)
let item2 = UIBarButtonItem(image: #imageLiteral(resourceName: "search icon"), style: .plain, target: self, action: #selector(searchPressed))
self.navigationItem.setLeftBarButtonItem(item2, animated: true)
let imageButton = UIButton(frame: CGRect(x: 0, y: 0, width: 0, height: navigationBarHeight))
let image = #imageLiteral(resourceName: "Stickiie Logo Main")
imageButton.setImage(image, for: UIControlState())
imageButton.imageView?.contentMode = .scaleAspectFit
imageButton.addTarget(self, action: #selector(refresh), for: .touchDown)
self.navigationItem.titleView? = imageButton
在 Xcode 9 之前:
Xcode9 之后: