dogo / SCLAlertView

Beautiful animated Alert View. Written in Objective-C
MIT License
3.5k stars 534 forks source link

Access a Button #242

Closed mukulm24 closed 7 years ago

mukulm24 commented 7 years ago
Include the following:
Reproduction Steps

1.Create a SCLAlertView 2.Add a button to it

Expected Result

How do i change the properties of this button on its tap.

let changeButton = alert.addButton("Change Password") { //button clicked //change button color ( i cannot use change button as it is inside its own initializer.) any other way than adding target manually) //button operations

}

Actual Result

Tell us what could be improved:

johnyluyte commented 7 years ago

Don't know if this is the right way to do it. But I usually use the showCustomSubview example to create my own button:

func showCustomSubview() {
    alert = SCLAlertView(appearance: appearance)
    alert.showInfo("title")        

    // Customize your button
    let confirmButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 100))    
    // Change event listener to "tap" if needed
    confirmButton.addTarget(self, action: #selector(self.onClickConfirmButton), for: .touchDown)

    let subview = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)
    subview.addSubview(confirmButton)
    alert.customSubview = subview
}

func onClickConfirmButton() {
    alert.hideView()
    // do something
}