Created
July 13, 2013 13:38
-
-
Save EmperiorEric/5990750 to your computer and use it in GitHub Desktop.
Looking for an elegant way to make two views dependent on each other, without being the triggers that create them. Basically in a UITableViewCell I have two labels that appear side-by-side. Their frames are obviously dependent on each other for this reason, but either could be nonexistent based. I calling self.label would lazy init them so you'd…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UILabel *)titleLabel | |
{ | |
if (!_titleLabel) { | |
CGFloat width = CGRectGetMinX(_detailLabel.frame); | |
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, width, CGRectGetHeight(self.infoView.bounds))]; | |
[self.infoView addSubview:_titleLabel]; | |
} | |
return _titleLabel; | |
} | |
- (UILabel *)detailLabel | |
{ | |
if (!_detailLabel) { | |
CGFloat width = 64.0; | |
_detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.infoView.bounds) - width, 0.0, width, CGRectGetHeight(self.infoView.bounds))]; | |
[self.infoView addSubview:_detailLabel]; | |
} | |
return _detailLabel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment