Rework app labels on iOS to reuse title UILabel and use correct size and insets

This commit is contained in:
Cameron Gutman 2019-09-14 12:59:40 -07:00
parent 62df1cd5ba
commit 202f968b98

View File

@ -147,25 +147,26 @@ static UIImage* noImage;
} }
if (noAppImage) { if (noAppImage) {
#if TARGET_OS_TV
_appLabel = [[UILabel alloc] init]; _appLabel = [[UILabel alloc] init];
[_appLabel setTextColor:[UIColor whiteColor]]; [_appLabel setTextColor:[UIColor whiteColor]];
[_appLabel setText:_app.name];
[_appLabel setFrame:self.frame];
#else
_appLabel = _appButton.titleLabel;
[_appButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_appButton setTitle:_app.name forState:UIControlStateNormal];
[_appButton setTitleEdgeInsets:UIEdgeInsetsMake(_appOverlay != nil ? _appOverlay.frame.size.height : 5, 5, 5, 5)];
#endif
[_appLabel setFont:[UIFont systemFontOfSize:24]];
[_appLabel setBaselineAdjustment:UIBaselineAdjustmentAlignCenters]; [_appLabel setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
[_appLabel setTextAlignment:NSTextAlignmentCenter]; [_appLabel setTextAlignment:NSTextAlignmentCenter];
[_appLabel setLineBreakMode:NSLineBreakByWordWrapping]; [_appLabel setLineBreakMode:NSLineBreakByWordWrapping];
[_appLabel setNumberOfLines:0]; [_appLabel setNumberOfLines:0];
[_appLabel setText:_app.name];
#if TARGET_OS_TV #if TARGET_OS_TV
[_appLabel setFont:[UIFont systemFontOfSize:24]];
[_appLabel setFrame: self.frame];
[_appButton addSubview:[self renderToImageView:noImage]]; [_appButton addSubview:[self renderToImageView:noImage]];
#else #else
// This padding doesn't work on Apple TV due to how we render into an ImageView
CGFloat padding = 4.f;
[_appLabel setFrame: CGRectMake(padding, padding, _appButton.frame.size.width - 2 * padding, _appButton.frame.size.height - 2 * padding)];
[_appButton addSubview:_appLabel];
[self addSubview:_appOverlay]; [self addSubview:_appOverlay];
#endif #endif
} }