forked from organicmaps/organicmaps
Merge pull request #284 from igrechuhin/ig-master
[ios] Fixed long titles layout in direction view.
This commit is contained in:
commit
3de164bd05
3 changed files with 42 additions and 10 deletions
|
@ -27,8 +27,7 @@ static CGFloat const kDirectionArrowSide = IPAD ? 260. : 160.;
|
|||
self.directionArrow.size = CGSizeMake(kDirectionArrowSide, kDirectionArrowSide);
|
||||
self.directionArrow.image = [UIImage imageNamed:IPAD ? @"direction_big" : @"direction_mini"];
|
||||
|
||||
NSString * const kFontName = @"HelveticaNeue";
|
||||
self.titleLabel.font = self.distanceLabel.font = IPAD ? [UIFont fontWithName:kFontName size:52.] : [UIFont fontWithName:kFontName size:32.];
|
||||
self.distanceLabel.font = IPAD ? [UIFont regular52] : [UIFont regular32];
|
||||
self.typeLabel.font = IPAD ? [UIFont regular24] : [UIFont regular16];
|
||||
|
||||
self.autoresizingMask = self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
||||
|
@ -46,15 +45,17 @@ static CGFloat const kDirectionArrowSide = IPAD ? 260. : 160.;
|
|||
[superview bringSubviewToFront:self];
|
||||
if (isLandscape)
|
||||
{
|
||||
CGFloat const defaultWidth = size.width - 3. * minimumBorderOffset - kDirectionArrowSide;
|
||||
[self resizeLabelsWithWidth:defaultWidth];
|
||||
CGFloat const defaultWidth = size.width - 2. * minimumBorderOffset - kDirectionArrowSide;
|
||||
[self resizeTitleWithWidth:defaultWidth];
|
||||
[self resizeTypeAndDistanceWithWidth:defaultWidth];
|
||||
CGFloat const titleOffset = 8.;
|
||||
CGFloat const typeOffset = 24.;
|
||||
CGFloat const arrowOffset = 24.;
|
||||
CGFloat const contentViewHeight = size.height - 2. * minimumBorderOffset;
|
||||
CGFloat const contentViewOffset = (size.width - self.titleLabel.width - minimumBorderOffset - self.directionArrow.width) / 2.;
|
||||
CGFloat const contentViewWidth = self.titleLabel.width + minimumBorderOffset + self.directionArrow.width;
|
||||
self.contentView.frame = CGRectMake(contentViewOffset, minimumBorderOffset, contentViewWidth, contentViewHeight);
|
||||
self.directionArrow.center = CGPointMake(kDirectionArrowSide / 2., self.contentView.height / 2.);
|
||||
self.directionArrow.center = CGPointMake(arrowOffset + kDirectionArrowSide / 2., self.contentView.height / 2.);
|
||||
CGFloat const directionArrowOffsetX = self.directionArrow.maxX + minimumBorderOffset;
|
||||
CGFloat const actualLabelsBlockHeight = self.titleLabel.height + titleOffset + self.typeLabel.height + typeOffset + self.distanceLabel.height;
|
||||
CGFloat const labelsBlockTopOffset = (contentViewHeight - actualLabelsBlockHeight) / 2.;
|
||||
|
@ -68,9 +69,10 @@ static CGFloat const kDirectionArrowSide = IPAD ? 260. : 160.;
|
|||
else
|
||||
{
|
||||
CGFloat const defaultWidth = size.width - 2. * minimumBorderOffset;
|
||||
[self resizeLabelsWithWidth:defaultWidth];
|
||||
[self resizeTitleWithWidth:defaultWidth];
|
||||
[self resizeTypeAndDistanceWithWidth:defaultWidth];
|
||||
CGFloat const titleOffset = IPAD ? 12. : 8.;
|
||||
CGFloat const arrowOffset = IPAD ? 80. : 40.;
|
||||
CGFloat const arrowOffset = IPAD ? 80. : 32.;
|
||||
CGFloat const contentViewActualHeight = self.titleLabel.height + titleOffset + self.typeLabel.height + 2. * arrowOffset + kDirectionArrowSide + self.distanceLabel.height;
|
||||
CGFloat const contentViewSize = size.height > contentViewActualHeight ? contentViewActualHeight : size.height;
|
||||
CGFloat const yOffset = (size.height - contentViewSize) / 2.;
|
||||
|
@ -86,10 +88,28 @@ static CGFloat const kDirectionArrowSide = IPAD ? 260. : 160.;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)resizeLabelsWithWidth:(CGFloat)width
|
||||
- (void)resizeTitleWithWidth:(CGFloat)width
|
||||
{
|
||||
self.titleLabel.width = self.typeLabel.width = self.distanceLabel.width = width;
|
||||
[self.titleLabel sizeToFit];
|
||||
CGFloat const fontSize = IPAD ? 52.0 : 32.0;
|
||||
CGFloat const minFontSize = IPAD ? 24.0 : 16.0;
|
||||
CGSize const superviewSize = self.superview.size;
|
||||
BOOL const isLandscape = superviewSize.width > superviewSize.height;
|
||||
CGFloat const minHeight = (isLandscape ? 0.6 : 0.3) * superviewSize.height;
|
||||
UIFont * font = self.distanceLabel.font;
|
||||
UILabel * label = self.titleLabel;
|
||||
for (CGFloat size = fontSize; size >= minFontSize; size -= 1.0)
|
||||
{
|
||||
label.font = [font fontWithSize:size];
|
||||
label.width = width;
|
||||
[label sizeToFit];
|
||||
if (label.height <= minHeight)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)resizeTypeAndDistanceWithWidth:(CGFloat)width
|
||||
{
|
||||
self.typeLabel.width = self.distanceLabel.width = width;
|
||||
[self.typeLabel sizeToFit];
|
||||
[self.distanceLabel sizeToFit];
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
+ (UIFont *)regular17;
|
||||
+ (UIFont *)regular18;
|
||||
+ (UIFont *)regular24;
|
||||
+ (UIFont *)regular32;
|
||||
+ (UIFont *)regular52;
|
||||
+ (UIFont *)medium10;
|
||||
+ (UIFont *)medium14;
|
||||
+ (UIFont *)medium16;
|
||||
|
|
|
@ -42,6 +42,16 @@ static NSString * const kBoldFont = @"HelveticaNeue-Bold";
|
|||
return [UIFont fontWithName:kRegularFont size:24];
|
||||
}
|
||||
|
||||
+ (UIFont *)regular32
|
||||
{
|
||||
return [UIFont fontWithName:kRegularFont size:32];
|
||||
}
|
||||
|
||||
+ (UIFont *)regular52
|
||||
{
|
||||
return [UIFont fontWithName:kRegularFont size:52];
|
||||
}
|
||||
|
||||
+ (UIFont *)medium10
|
||||
{
|
||||
return [UIFont fontWithName:kMediumFont size:10];
|
||||
|
|
Loading…
Add table
Reference in a new issue