Now I edit this font's type/size etc and expect the fonts of those labels to change too, which does not happen. I basically need to apply a single font to multiple labels and I know this can be done with an outlet collection but i'd just like some help in understanding the flaw in my logic here so here's my code...
self.labelFont = [UIFont fontWithName:@"System" size:12];
self.label1.font = self.labelFont;
self.label2.font = self.labelFont;
self.label3.font = self.labelFont;
self.labelFont = [UIFont fontWithName:@"Courier" size:30];
Thank
In your code you create two objects, [UIFont fontWithName:@"System" size:12]
, and [UIFont fontWithName:@"Courier" size:30]
.
Initially, your labelFont
variable points to the first font object. Then you copy that pointer in the assignments to fonts of the three labels. At this moment, you have four pointers referencing the same object - namely, the object returned by the [UIFont fontWithName:@"System" size:12]
call.
Next, you change labelFont
to point to [UIFont fontWithName:@"Courier" size:30]
. Once you do that, the labelFont
starts pointing to that new object; it no longer points to the old object. However, the three labels are still pointing to the old font, so their appearance does not change.
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