internal virtual void ApplyFormatter(NSFormatter formatter) { if (textField != null && formatter != null) { textField.Formatter = formatter; } }
public static string ShowInputBoxEx(string title, string informativeText, string defaultValue, string placeholder = "", int width = 0, NSFormatter textFormatter = null) { NSAlert alert = new NSAlert(); alert.AddButton("OK"); alert.AddButton("Cancel"); if (!string.IsNullOrEmpty(title)) { alert.MessageText = title; } if (!string.IsNullOrEmpty(informativeText)) { alert.InformativeText = informativeText; } CGRect textFieldRect; if (width <= 0) { width = 300; } textFieldRect = new CGRect(0, 0, width, 36); CustomTextField tf = new CustomTextField(textFieldRect); tf.Alignment = NSTextAlignment.Center; tf.Font = NSFont.SystemFontOfSize(16); var dc = new NSDateComponentsFormatter(); dc.UnitsStyle = NSDateComponentsFormatterUnitsStyle.Full; dc.AllowedUnits = NSCalendarUnit.Minute; if (textFormatter != null) { tf.Formatter = textFormatter; } if (!string.IsNullOrEmpty(defaultValue)) { tf.StringValue = defaultValue; } if (!string.IsNullOrEmpty(placeholder)) { tf.PlaceholderString = placeholder; } alert.AccessoryView = tf; alert.Window.InitialFirstResponder = tf; nint result = alert.RunModal(); if (result == (int)NSAlertButtonReturn.First) { return(tf.StringValue); } return(null); }
internal static void SetFormatter(this NumericSpinEditor control, NSFormatter formatter) { IntPtr pointer = formatter != null ? formatter.Handle : IntPtr.Zero; void_objc_msgSend_intptr(control.NumericEditor.Handle, selSetFormatter_Handle, pointer); }