Reputation: 83
I was wondering if it is possible to get the name of a UILabel
(not the text).
Something like this:
if([label.name is equalToString:key]){
//do something
}
I know label.name
doesn't exist but maybe there is something equivalent. How can I do this?
Upvotes: 5
Views: 1032
Reputation: 8588
You could subclass UILabel:
// Objective-C
#import <UIKit/UIKit.h>
@interface NMLabel : UILabel
@property (nonatomic, readwrite) NSString *name;
@end
// Swift
import UIKit
class NMLabel : UILabel {
var name : String = ""
}
Or at the most basic of levels you can use the already existent tag
property (in both Objective-C or Swift):
label.tag = 5
// Objective-C
NSLog(@"%d", label.tag); // prints 5
// Swift
print(label.tag) // prints 5
Upvotes: 4