jmcastel jmcastel - 6 months ago 74
iOS Question

Swift : Hide button in subview

I am trying to hide a UIButton in a subView when a function is fired.
I have multiple views with that hierarchy :

var takePhotoButton : UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton

takePhotoButton.addTarget(self, action:"takePhoto", forControlEvents:UIControlEvents.TouchUpInside)

var savePhotoButton : UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton

let view2:UIView = UIView(frame: CGRectMake(0, 0, 320, 568))


I want to hide the takePhotoButton when the following func is fired, how could I do that ?

func takePhoto(takePhotoButton: UIButton!) {
takePhotoButton.hidden = true


You have to make the UIButton a property of the class if you want to keep a reference to it. Then you can access it using self.takePhotoButton.