Skip to content

Instantly share code, notes, and snippets.

@EmperiorEric
Created July 13, 2013 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EmperiorEric/5990750 to your computer and use it in GitHub Desktop.
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…
- (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