Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden status of WKInterfaceButton in WatchKit

Is there a way to check the current hidden status of WKInterfaceButton in WatchKit?

like image 521
Justin Domnitz Avatar asked Jan 25 '26 13:01

Justin Domnitz


2 Answers

It looks like you cannot do that. But you can store your own variable with state and use it.

Below you can check definition of button's parent class.

public class WKInterfaceObject : NSObject {

    public func setHidden(hidden: Bool)
    public func setAlpha(alpha: CGFloat)

    @available(watchOS 2.0, *)
    public func setHorizontalAlignment(horizontalAlignment: WKInterfaceObjectHorizontalAlignment)
    @available(watchOS 2.0, *)
    public func setVerticalAlignment(verticalAlignment: WKInterfaceObjectVerticalAlignment)

    public func setWidth(width: CGFloat)
    public func setHeight(height: CGFloat)
    @available(watchOS 2.0, *)
    public func setRelativeWidth(width: CGFloat, withAdjustment adjustment: CGFloat)
    @available(watchOS 2.0, *)
    public func setRelativeHeight(height: CGFloat, withAdjustment adjustment: CGFloat)

    @available(watchOS 2.0, *)
    public func sizeToFitWidth()
    @available(watchOS 2.0, *)
    public func sizeToFitHeight()

    public var interfaceProperty: String { get } // same as controller's property name
}
like image 97
Arsen Avatar answered Jan 27 '26 01:01

Arsen


The WKInterfaceButton class have a method inherited from WKInterfaceObject class entitled setHidden: that you can use to show/hide the button and with an auxiliar variable you can set programmatically the status of the WKInterfaceButton.

Something like the following example:

class InterfaceController: WKInterfaceController {

   @IBOutlet var button: WKInterfaceButton!     

   var buttonIsHidden: Bool!

   override func awakeWithContext(context: AnyObject?) {
      self.changeStatusOfButton(true)
   }

   private func changeStatusOfButton(status: Bool) {

      // set programmatically the status of the button to hide/show 
      self.activityButton.setHidden(status)

      // save the current status
      self.buttonIsHidden = status
   }

   private func showButtonAgain() {
       self.changeStatusOfButton(false)
   }
}

And whenever you want to know if the button is hidden/show you only need to check the variable buttonIsHidden.

I hope this help you.

like image 40
Vkt0r Avatar answered Jan 27 '26 02:01

Vkt0r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!