diff options
author | Lloyd Sheng <i@lloydsheng.com> | 2019-01-30 15:39:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 15:39:29 +0800 |
commit | e22d28c285c1543ebbf75d205f0129e74b0fbb8a (patch) | |
tree | 09e5ebae51df26d3e68cb8f0f95ff0296673b808 /platform/ios/src/MGLScaleBar.mm | |
parent | 44fbba8514554dd05a0d8abc3f33f21840a73033 (diff) | |
download | qtlocation-mapboxgl-e22d28c285c1543ebbf75d205f0129e74b0fbb8a.tar.gz |
[ios] Enable customize positions of mapview ornaments (#13556)
* APIs for customize positions of ornaments
* Adopt anchors layout
* Remove iOS8 layout code
Diffstat (limited to 'platform/ios/src/MGLScaleBar.mm')
-rw-r--r-- | platform/ios/src/MGLScaleBar.mm | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/platform/ios/src/MGLScaleBar.mm b/platform/ios/src/MGLScaleBar.mm index f17d7b7ad2..caa5157a49 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,6 +94,7 @@ static const CGFloat MGLBarHeight = 4; static const CGFloat MGLFeetPerMeter = 3.28084; @interface MGLScaleBarLabel : UILabel + @end @implementation MGLScaleBarLabel @@ -184,7 +185,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084; #pragma mark - Dimensions - (CGSize)intrinsicContentSize { - return CGSizeMake(self.actualWidth, 16); + return CGSizeMake(self.actualWidth + self.lastLabelWidth/2, 16); } - (CGFloat)actualWidth { @@ -194,8 +195,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084; - (CGFloat)maximumWidth { CGFloat fullWidth = CGRectGetWidth(self.superview.bounds); - CGFloat padding = [self usesRightToLeftLayout] ? fullWidth - CGRectGetMaxX(self.frame) : CGRectGetMinX(self.frame); - return floorf(fullWidth / 2 - padding); + return floorf(fullWidth / 2); } - (CGFloat)unitsPerPoint { @@ -256,12 +256,9 @@ static const CGFloat MGLFeetPerMeter = 3.28084; [self updateVisibility]; self.row = [self preferredRow]; - + CGSize size = self.intrinsicContentSize; - self.frame = CGRectMake(CGRectGetMinX(self.frame), - CGRectGetMinY(self.frame), - size.width, - size.height); + self.bounds = CGRectMake(0, 0, size.width, size.height); } - (void)updateVisibility { @@ -371,7 +368,9 @@ 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; } @@ -421,7 +420,7 @@ static const CGFloat MGLFeetPerMeter = 3.28084; } - (void)layoutLabels { - CGFloat barWidth = round(self.bounds.size.width / self.bars.count); + CGFloat barWidth = round(self.actualWidth / self.bars.count); BOOL RTL = [self usesRightToLeftLayout]; NSUInteger i = RTL ? self.bars.count : 0; for (UIView *label in self.labelViews) { |