Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZdenoIT - patch 1 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

ZdenoIT - patch 1 #17

wants to merge 3 commits into from

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