Setting text color for all elements in IBOutletCollection

I have several IBOutlet and use them with IBOutletCollection:

    @interface IBOutletCollectionViewController : UIViewController {


    IBOutletCollection (UILabel) NSArray *multipleLabels;

}

@property (nonatomic , retain) IBOutletCollection (UILabel) NSArray *multipleLabels;

@end

but when I want to use the UILable properties, the compiler reports this error:

request for a textColor member in something not a structure or union

I think it's because of NSArray! is there any solution for this?

+3
source share
1 answer

You can use Key-Value Coding to set a property for each instance of the label in the array:

[multipleLabels setValue:[UIColor redColor] forKey:@"textColor"];

"IBOutletCollection (UILabel)" may be omitted in the iVar declaration if it is used in the property declaration.

- "makeObjectsPerformSelector:" NSArray:

[multipleLabels makeObjectsPerformSelector:@selector(setTextColor:) withObject:[UIColor redColor]];
+12

Source: https://habr.com/ru/post/1781205/


All Articles