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?
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
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