I am building a custom keyboard, in which there are about 50 UIButton keys. I'd like to put some grouping information for each key, e.g., numbers, alphabets, cursors, etc.
The first thing comes to mind is by mean of the tag field (100 for alphabets, 200 for numbers, ... etc.)
Another option is by means of a category with Associative References.
However, both methods are not very Interface Builder-friendly. Any other option?
You wrote
I'd like to put some grouping information for each key, e.g., numbers, alphabets, cursors, etc.
Why not use IBOutletCollections?
You can declare arrays for each of "numbers, alphabets, cursors":
@property (nonatomic) IBOutletCollection(UIButton) NSArray *numberButtons;
@property (nonatomic) IBOutletCollection(UIButton) NSArray *letterButtons;
@property (nonatomic) IBOutletCollection(UIButton) NSArray *cursorButtons;
and easily hook them up in interface builder:

Probably the cleanest way to do it and handle everything in the same subclass/category is by using User Defined Runtime Attributes

For the example above, you should have at least one method:
-(void) setLocalizedKey:(NSString *) key;
//(NSString *) localizedKey; this is optional
or property:
@property(nonatomic, strong) NSString * localizedKey;
declared and implemented(or @synthesize) in your UIButton subclass or category if you fancy associative references (or you don't need storage or don't have access to the class itself).
In the example above, the value of key will be HOW_IT_WORKS for that specific instance. This is the way I usually handle localisation, but should serve your purpose too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With