Reputation: 9140
Any of you knows how can set NSTextField to only accept numbers(int)?
Let me explain. I got my NSTextField:
@IBOutlet weak var txtBoxField: NSTextField!
But I can type any string and what I want is just to be able to type numbers.
I'll really appreciate your help.
Upvotes: 1
Views: 1060
Reputation: 3439
In IB, get an NSNumberFormatter
object and drop it onto your NSTextField
. This attaches a number formatter object to that text field. In the object browser, it should look like this:
Now select the Number Formatter
object and configure the kind, style, and range of numbers that it should allow:
Choose a style of None
if you just want whole integers.
If you must do this programmatically, see NSNumberFormatter
to create and configure the formatter object then use that to set the text field's formatter
property.
Upvotes: 3