Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we get UILabel's name?

Tags:

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?

like image 239
miDark Avatar asked Sep 02 '16 14:09

miDark


1 Answers

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
like image 158
Wyetro Avatar answered Sep 22 '22 17:09

Wyetro