summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLScaleBar.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src/MGLScaleBar.mm')
-rw-r--r--platform/ios/src/MGLScaleBar.mm21
1 files changed, 11 insertions, 10 deletions
diff --git a/platform/ios/src/MGLScaleBar.mm b/platform/ios/src/MGLScaleBar.mm
index caa5157a49..f17d7b7ad2 100644
--- a/platform/ios/src/MGLScaleBar.mm
+++ b/platform/ios/src/MGLScaleBar.mm
@@ -86,7 +86,7 @@ static const MGLRow MGLImperialTable[] ={
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic) NSCache* labelImageCache;
@property (nonatomic) MGLScaleBarLabel* prototypeLabel;
-@property (nonatomic) CGFloat lastLabelWidth;
+
@end
@@ -94,7 +94,6 @@ static const CGFloat MGLBarHeight = 4;
static const CGFloat MGLFeetPerMeter = 3.28084;
@interface MGLScaleBarLabel : UILabel
-
@end
@implementation MGLScaleBarLabel
@@ -185,7 +184,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084;
#pragma mark - Dimensions
- (CGSize)intrinsicContentSize {
- return CGSizeMake(self.actualWidth + self.lastLabelWidth/2, 16);
+ return CGSizeMake(self.actualWidth, 16);
}
- (CGFloat)actualWidth {
@@ -195,7 +194,8 @@ static const CGFloat MGLFeetPerMeter = 3.28084;
- (CGFloat)maximumWidth {
CGFloat fullWidth = CGRectGetWidth(self.superview.bounds);
- return floorf(fullWidth / 2);
+ CGFloat padding = [self usesRightToLeftLayout] ? fullWidth - CGRectGetMaxX(self.frame) : CGRectGetMinX(self.frame);
+ return floorf(fullWidth / 2 - padding);
}
- (CGFloat)unitsPerPoint {
@@ -256,9 +256,12 @@ static const CGFloat MGLFeetPerMeter = 3.28084;
[self updateVisibility];
self.row = [self preferredRow];
-
+
CGSize size = self.intrinsicContentSize;
- self.bounds = CGRectMake(0, 0, size.width, size.height);
+ self.frame = CGRectMake(CGRectGetMinX(self.frame),
+ CGRectGetMinY(self.frame),
+ size.width,
+ size.height);
}
- (void)updateVisibility {
@@ -368,9 +371,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084;
CLLocationDistance barDistance = multiplier * i;
UIImage *image = [self cachedLabelImageForDistance:barDistance];
- if (i == self.row.numberOfBars) {
- self.lastLabelWidth = image.size.width;
- }
+
labelView.layer.contents = (id)image.CGImage;
labelView.layer.contentsScale = image.scale;
}
@@ -420,7 +421,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084;
}
- (void)layoutLabels {
- CGFloat barWidth = round(self.actualWidth / self.bars.count);
+ CGFloat barWidth = round(self.bounds.size.width / self.bars.count);
BOOL RTL = [self usesRightToLeftLayout];
NSUInteger i = RTL ? self.bars.count : 0;
for (UIView *label in self.labelViews) {