I am currently using unified storyboards (with size classes). For 1 of my views, the difference in design between the wAny hAny and the wRegular hRegular size classes is significant enough that altering the constraints for the subviews based on size class is not enough.
A simplified example: I have a UILabel in the wAny hAny size class called "First_Name_Label". While I wish to reuse this UILabel for the wRegular hRegular size class, the design is too different, so I add a UILabel for the wRegular hRegular size class to replicate the purpose of the "First_Name_Label", and I call it "First_Name_Label 2". The "First_Name_Label" is only installed in the wAny hAny size class, and "First_Name_Label 2" is only installed in the wRegular hRegular size class.
In my code, I want to set the text for the label:
self.First_Name_Label.text = "my first name"
But I need to do it for the other size class as well, and my code would be as follows:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomIpad) {
self.First_Name_Label2.text = "my first name"
} else {
self.First_Name_Label.text = "my first name"
}
This seems very cumbersome, basically doubling my current code. I'm sure there's a more elegant and efficient way to reference these 2 IBOutlets (each belonging to a different size class) at once.
You can't connect an IBOutlet property with more than one object.
But you can use the same tag on those labels and get to them like this: