2

I'm trying to set 10 buttons with the same font and style but don't want to create 10 IBOutlets. I've never used a collection before but I believe that is how I minimise code when working with outlets? How can I put this code into a referencing outlet collection and apply it to all my buttons?

ViewController.h

IBOutlet UIButton *label;

ViewController.m (ViewDidLoad)

[label setFont:[UIFont fontWithName:@"CooperBlack" size:14]];
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
BrownEye
  • 979
  • 2
  • 12
  • 21
  • You Can use `Custom Cell` as using `UICollectionViewCell` – Buntylm Feb 21 '14 at 08:35
  • 1
    possible duplicate of [How can I use IBOutletCollection to connect multiple UIImageViews to the same outlet?](http://stackoverflow.com/questions/15836930/how-can-i-use-iboutletcollection-to-connect-multiple-uiimageviews-to-the-same-ou) – Desdenova Feb 21 '14 at 08:37

1 Answers1

3

Here is your properties outlets:

@property IBOutletCollection(UILabel) NSArray *labels;

And then:

// somewhere in your code
for(UILabel *lbl in self.labels) {
        [lbl setFont:[UIFont systemFontOfSize:15]];
    }
Basheer_CAD
  • 4,908
  • 24
  • 36
  • This won't work. I believe he needed `UIButton` not `UILabel`. – Desdenova Feb 21 '14 at 08:38
  • He can change the type to UIButton. @property IBOutletCollection(UIButton), What is the big deal ? – Basheer_CAD Feb 21 '14 at 08:40
  • I've put the @property just outside of the interface ViewController in .h and the for loop in the view did load in .m but in storyboard I can't set the button to new referencing collection. Any ideas why? – BrownEye Feb 21 '14 at 09:19
  • Remember your collection should be of type UIButton, not label. @BrownEye. – Basheer_CAD Feb 21 '14 at 09:20