Skip to content

ZdenoIT - patch 1#17

Open
ZdenoIT wants to merge 3 commits intoxtrinch:masterfrom
ZdenoIT:ZdenoIT-patch-1
Open

ZdenoIT - patch 1#17
ZdenoIT wants to merge 3 commits intoxtrinch:masterfrom
ZdenoIT:ZdenoIT-patch-1

Conversation

@ZdenoIT
Copy link

@ZdenoIT ZdenoIT commented Apr 24, 2018

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() {

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant