diff options
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs new file mode 100644 index 00000000..e74fed8d --- /dev/null +++ b/Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +#if __UNIFIED__ +using UIKit; + +#else +using MonoTouch.UIKit; +#endif + +namespace Xamarin.Forms.Platform.iOS +{ + public static class Extensions + { + public static void ApplyKeyboard(this IUITextInput textInput, Keyboard keyboard) + { + textInput.AutocapitalizationType = UITextAutocapitalizationType.None; + textInput.AutocorrectionType = UITextAutocorrectionType.No; + textInput.SpellCheckingType = UITextSpellCheckingType.No; + + if (keyboard == Keyboard.Default) + { + textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences; + textInput.AutocorrectionType = UITextAutocorrectionType.Default; + textInput.SpellCheckingType = UITextSpellCheckingType.Default; + textInput.KeyboardType = UIKeyboardType.Default; + } + else if (keyboard == Keyboard.Chat) + { + textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences; + textInput.AutocorrectionType = UITextAutocorrectionType.Yes; + } + else if (keyboard == Keyboard.Email) + textInput.KeyboardType = UIKeyboardType.EmailAddress; + else if (keyboard == Keyboard.Numeric) + textInput.KeyboardType = UIKeyboardType.DecimalPad; + else if (keyboard == Keyboard.Telephone) + textInput.KeyboardType = UIKeyboardType.PhonePad; + else if (keyboard == Keyboard.Text) + { + textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences; + textInput.AutocorrectionType = UITextAutocorrectionType.Yes; + textInput.SpellCheckingType = UITextSpellCheckingType.Yes; + } + else if (keyboard == Keyboard.Url) + textInput.KeyboardType = UIKeyboardType.Url; + else if (keyboard is CustomKeyboard) + { + var custom = (CustomKeyboard)keyboard; + var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence; + var spellcheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck; + var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions; + + textInput.AutocapitalizationType = capitalizedSentenceEnabled ? UITextAutocapitalizationType.Sentences : UITextAutocapitalizationType.None; + textInput.AutocorrectionType = suggestionsEnabled ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No; + textInput.SpellCheckingType = spellcheckEnabled ? UITextSpellCheckingType.Yes : UITextSpellCheckingType.No; + } + } + + internal static DeviceOrientation ToDeviceOrientation(this UIDeviceOrientation orientation) + { + switch (orientation) + { + case UIDeviceOrientation.Portrait: + return DeviceOrientation.Portrait; + case UIDeviceOrientation.PortraitUpsideDown: + return DeviceOrientation.PortraitDown; + case UIDeviceOrientation.LandscapeLeft: + return DeviceOrientation.LandscapeLeft; + case UIDeviceOrientation.LandscapeRight: + return DeviceOrientation.LandscapeRight; + default: + return DeviceOrientation.Other; + } + } + } +}
\ No newline at end of file |