public void _commonInit(){ NSMutableDictionary buttonDictionary = new NSMutableDictionary(); /*const*/ MMNumberKeyboardButton numberMin = MMNumberKeyboardButton.NumberMin; /*const*/ MMNumberKeyboardButton numberMax = MMNumberKeyboardButton.NumberMax; UIFont buttonFont = UIFont.FromName("Helvetica-Bold", 20f); if (buttonFont.RespondsToSelector(new Selector ( "weight:"))) { buttonFont = UIFont.SystemFontOfSize(28.0f ,/*weight*/ UIFontWeight.Light); } else { buttonFont = UIFont.FromName("HelveticaNeue-Light" ,/*size*/ 28.0f); } UIFont doneButtonFont = UIFont.SystemFontOfSize(17.0f); //for (MMNumberKeyboardButton key = numberMin;key < numberMax; key++) { foreach (MMNumberKeyboardButton key in Enum.GetValues(typeof(MMNumberKeyboardButton))) { UIButton button = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.White); string Title = (key - numberMin).ToString(); button.SetTitle(Title ,/*forState*/ UIControlState.Normal); button.TitleLabel.Font = buttonFont; int keyInt = (int)key; Console.WriteLine ("keyInt:"+keyInt); var number = new NSNumber (keyInt); Console.WriteLine ("number:"+number); buttonDictionary.Add(button ,number); } UIImage backspaceImage = this._keyboardImageNamed("MMNumberKeyboardDeleteKey.png"); UIImage dismissImage = this._keyboardImageNamed("MMNumberKeyboardDismissKey.png"); _MMNumberKeyboardButton backspaceButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Gray); backspaceButton.SetImage( /*setImage*/ backspaceImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate ), UIControlState.Normal); backspaceButton.AddTarget( /*addTarget*/ this ,/*action*/ new Selector ("_backspaceRepeat: ") ,/*.forContinuousPressWithTimeInterval*/ 0.15f); buttonDictionary.Add(backspaceButton ,/*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Backspace)); UIButton specialButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Gray); buttonDictionary.Add(specialButton ,/*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Special)); UIButton doneButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Done); doneButton.TitleLabel.Font = doneButtonFont; doneButton.SetTitle(UIKitLocalizedString("Done") ,/*forState*/ UIControlState.Normal); buttonDictionary.Add(doneButton ,/*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Done)); _MMNumberKeyboardButton decimalPointButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.White); NSLocale locale = this.locale ?? NSLocale.CurrentLocale; string decimalSeparator = @".";//locale.ObjectForKey(NSLocale.DecimalSeparator); decimalPointButton.SetTitle(decimalSeparator ?? "." ,/*forState*/ UIControlState.Normal); buttonDictionary.Add(decimalPointButton ,/*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.DecimalPoint)); foreach (UIButton button in buttonDictionary.Values) { button.ExclusiveTouch = true; button.AddTarget(this ,/*action*/ new Selector ("_buttonInput") ,/*forControlEvents*/ UIControlEvent.TouchUpInside); button.AddTarget(this ,/*action*/ new Selector ("_buttonPlayClick") ,/*forControlEvents*/ UIControlEvent.TouchDown); this.AddSubview(button); } UIPanGestureRecognizer highlightGestureRecognizer = new UIPanGestureRecognizer(this ,/*action*/ new Selector ("_handleHighlightGestureRecognizer")); this.AddGestureRecognizer(highlightGestureRecognizer); this.buttonDictionary = buttonDictionary; // Add default action. this.configureSpecialKeyWithImage(dismissImage ,/*target*/ this ,/*action*/ new Selector ("_dismissKeyboard")); // Size to fit. this.SizeToFit(); }
public void _commonInit() { NSMutableDictionary buttonDictionary = new NSMutableDictionary(); /*const*/ MMNumberKeyboardButton numberMin = MMNumberKeyboardButton.NumberMin; /*const*/ MMNumberKeyboardButton numberMax = MMNumberKeyboardButton.NumberMax; UIFont buttonFont = UIFont.FromName("Helvetica-Bold", 20f); if (buttonFont.RespondsToSelector(new Selector("weight:"))) { buttonFont = UIFont.SystemFontOfSize(28.0f, /*weight*/ UIFontWeight.Light); } else { buttonFont = UIFont.FromName("HelveticaNeue-Light", /*size*/ 28.0f); } UIFont doneButtonFont = UIFont.SystemFontOfSize(17.0f); //for (MMNumberKeyboardButton key = numberMin;key < numberMax; key++) { foreach (MMNumberKeyboardButton key in Enum.GetValues(typeof(MMNumberKeyboardButton))) { UIButton button = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.White); string Title = (key - numberMin).ToString(); button.SetTitle(Title, /*forState*/ UIControlState.Normal); button.TitleLabel.Font = buttonFont; int keyInt = (int)key; Console.WriteLine("keyInt:" + keyInt); var number = new NSNumber(keyInt); Console.WriteLine("number:" + number); buttonDictionary.Add(button, number); } UIImage backspaceImage = this._keyboardImageNamed("MMNumberKeyboardDeleteKey.png"); UIImage dismissImage = this._keyboardImageNamed("MMNumberKeyboardDismissKey.png"); _MMNumberKeyboardButton backspaceButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Gray); backspaceButton.SetImage(/*setImage*/ backspaceImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal); backspaceButton.AddTarget(/*addTarget*/ this, /*action*/ new Selector("_backspaceRepeat: "), /*.forContinuousPressWithTimeInterval*/ 0.15f); buttonDictionary.Add(backspaceButton, /*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Backspace)); UIButton specialButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Gray); buttonDictionary.Add(specialButton, /*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Special)); UIButton doneButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.Done); doneButton.TitleLabel.Font = doneButtonFont; doneButton.SetTitle(UIKitLocalizedString("Done"), /*forState*/ UIControlState.Normal); buttonDictionary.Add(doneButton, /*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.Done)); _MMNumberKeyboardButton decimalPointButton = new _MMNumberKeyboardButton(MMNumberKeyboardButtonType.White); NSLocale locale = this.locale ?? NSLocale.CurrentLocale; string decimalSeparator = @"."; //locale.ObjectForKey(NSLocale.DecimalSeparator); decimalPointButton.SetTitle(decimalSeparator ?? ".", /*forState*/ UIControlState.Normal); buttonDictionary.Add(decimalPointButton, /*forKey*/ NSObject.FromObject(MMNumberKeyboardButton.DecimalPoint)); foreach (UIButton button in buttonDictionary.Values) { button.ExclusiveTouch = true; button.AddTarget(this, /*action*/ new Selector("_buttonInput"), /*forControlEvents*/ UIControlEvent.TouchUpInside); button.AddTarget(this, /*action*/ new Selector("_buttonPlayClick"), /*forControlEvents*/ UIControlEvent.TouchDown); this.AddSubview(button); } UIPanGestureRecognizer highlightGestureRecognizer = new UIPanGestureRecognizer(this, /*action*/ new Selector("_handleHighlightGestureRecognizer")); this.AddGestureRecognizer(highlightGestureRecognizer); this.buttonDictionary = buttonDictionary; // Add default action. this.configureSpecialKeyWithImage(dismissImage, /*target*/ this, /*action*/ new Selector("_dismissKeyboard")); // Size to fit. this.SizeToFit(); }