I need a way to get all UILabel
s within a UIView
without having to go through all the views within the UIView
.
I have many other type of views, UIButton
s, UIImageView
s and it would be too long to go through all of them when I just need the UILabel
s.
I'm trying to avoid something like this:
for (UIView *view in myView.subviews)
{
if([view isKindOfClass:[UILabel class]])
{
UILabel *lbl = (UILabel*)view;
}
}
Is it possible or am I dreaming?
Create an NSArray
ivar which you can add all the UILabel
's to.
If you do it in code then as you create the UILabel
just do
NSMutableArray *labels = [[NSMutableArray alloc] init];
// Repeat this for al labels
UILabel *label = [[UILabel alloc] in...
[labels addObject:label];
// Then
self.labels = [labels copy];
If you use IB the declare your property like this
@property (nonatomic, strong) IBOutletCollection(UILabel) NSArray *labels;
and connect all the labels up to this.
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