Can the value of the Identity Label be accessed in

2019-06-21 06:00发布

问题:

I have a number of labels in Interface builder which all have their identity label set (Identity inspector > Identity > Label.

I would now like to access these labels in my code. Is this generally possible or is this only present within Interface builder?

回答1:

It would not be possible to access each labels Identity inspector > Identity > Label in your code. To better understand what the Identity label does, check out this link:

Label property in identity inspector

It would probably be better if you just accessed the label using the defined IBOulet. If you want to try something that is similar you could just set the tag property like so:

label.tag = 1;

Give each label a unique tag and you should be able to access it using

UILabel *label = [self.view viewWithTag:1];



回答2:

You can give different tags to your labels and then access labels by tags.