MRCountryPicker icon indicating copy to clipboard operation
MRCountryPicker copied to clipboard

ZdenoIT - patch 1

Open ZdenoIT opened this issue 6 years ago • 0 comments

Filter for EU countries now it can be use programmatically in picker getter for actual selectedCountry without delegate public Struct "Country", public Constructor with frame as parameter

countrycodepicker

Example for use programmatically:

var selectedCountryCode: String! @IBOutlet weak var countryCodeButton: UIButton!

@IBAction func onClickButton() { self.showCountryPickerInActionSheet() }

// MARK: - CountryPicker inside UIAlertController

func showCountryPickerInActionSheet() {

    let message = "\n\n\n\n\n\n\n\n\n"
    let alert = UIAlertController(title: NSLocalizedString("CountryCodePicker", comment: ""), message: message, preferredStyle: UIAlertControllerStyle.actionSheet);
    alert.isModalInPopover = true

    let pickerFrame: CGRect = CGRect(x: 0, y: 30, width: alert.view.frame.size.width - 20, height: 216)

    // init country picker !!
    let countryCodePicker = MRCountryPicker(frame: pickerFrame, onlyEU: true)

    countryCodePicker.setCountry(self.selectedCountryCode)
    countryCodePicker.setLocale(Locale.current.languageCode!)

    alert.view.addSubview(countryCodePicker);

    let noAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style:UIAlertActionStyle.destructive, handler: {(alert: UIAlertAction) in
        self.btnCancelPressedInCountryPickerActionSheet()
    })
    alert.addAction(noAction)

    let okAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style:UIAlertActionStyle.default, handler: {(alert: UIAlertAction) in
       self.btnOKPressedInCountryPickerActionSheet(selectedCode: countryCodePicker.selectedCountry!.code!, selectedPhoneCode: countryCodePicker.selectedCountry!.phoneCode!)
    })

    alert.addAction(okAction)

    self.present(alert, animated: true, completion: nil);
}

func btnOKPressedInCountryPickerActionSheet(selectedCode: String, selectedPhoneCode: String) {
    self.countryCodeButton.setTitle(selectedCode + " " + selectedPhoneCode, for: .normal)
    self.selectedCountryCode = selectedCode
}

func btnCancelPressedInCountryPickerActionSheet() {

}

ZdenoIT avatar Apr 24 '18 14:04 ZdenoIT