vikmeup / SCLAlertView-Swift

Beautiful animated Alert View. Written in Swift
MIT License
5.31k stars 764 forks source link

How to embed a UIPickerView into custom alert? #293

Open LukeSmith16 opened 7 years ago

LukeSmith16 commented 7 years ago

How do i go about embedding a uipickerview into a custom alert? Is it possible? Thanks

elgartoinf commented 6 years ago

regards! I used this solution

      //quit done button
        let appearance = SCLAlertView.SCLAppearance(
            showCloseButton: false
        )
        //init sclalertview object
        let alert = SCLAlertView(appearance: appearance)
        let subview = UIView(frame:CGRect(x: 0, y: 0, width: 120, height: 90))
        let picker = UIPickerView()
        picker.frame = CGRect(x: 0, y: 0, width: 120, height: 90)
        picker.delegate = alert
        subview.addSubview(picker)
        alert.customSubview = subview
        alert.showTitle(
            NSLocalizedString("title",comment:""),
            subTitle: NSLocalizedString("text",comment:""),
            style: .success,
            colorStyle: 0xCE2200,
            colorTextButton: 0xFFFFFF
        )

you must also create this extension

extension SCLAlertView: UIPickerViewDataSource, UIPickerViewDelegate{
    public func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return 10
    }

    public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
         return "First \(row)"
    }
}
iamir4g commented 5 years ago

work perfectly how to get which elements select in pickerview? thank