简体   繁体   中英

Xcode 6.3.1, Swift, iOS 8 Interface Builder - Uninstall button when landscape

Is it possible to uninstall a button when the device is in landscape?

I would have thought I could uninstall a button in the same way I uninstall a constraint - yet I can't work it out.

Found it in the interface builder:

  1. Set Interface builder to landscape (wAny hCompact)
  2. Select the button (View Controller > View > Button)
  3. Attributes Inspector (scroll all the way to the bottom)
  4. Uncheck 'Installed'

Here is one way:

@IBOutlet weak var btn_MyButton: UIButton!

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
    switch UIDevice.currentDevice().orientation{
    case .LandscapeLeft:
        btn_MyButton.hidden = true
    case .LandscapeRight:
        btn_MyButton.hidden = true
    default:
        btn_MyButton.hidden = false
    }       
}

You can remove your button or hide it

btn.removeFromSuperview()
//or
btn.hidden = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM