This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Show scale control #7432
Closed
Closed
Show scale control #7432
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface MGLScaleControlView : UIView | ||
|
||
- (void)updateWithZoomLevel:(double)zoomLevel metersPerPoint:(CLLocationDistance)metersPerPoint; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#import "MGLScaleControlView.h" | ||
|
||
@interface MGLScaleControlView() | ||
@property (nonatomic, assign) double zoomLevel; | ||
@property (nonatomic, assign) CLLocationDistance metersPerPoint; | ||
@property (nonatomic) NSArray *labels; | ||
@property (nonatomic) NSArray *bars; | ||
@property (nonatomic) UILabel *debugLabel; | ||
@end | ||
|
||
@implementation MGLScaleControlView | ||
|
||
- (void)updateWithZoomLevel:(double)zoomLevel metersPerPoint:(CLLocationDistance)metersPerPoint { | ||
self.zoomLevel = zoomLevel; | ||
self.metersPerPoint = metersPerPoint; | ||
} | ||
|
||
- (void)setZoomLevel:(double)zoomLevel { | ||
_zoomLevel = zoomLevel; | ||
[self.debugLabel setText:[NSString stringWithFormat:@"%0.2f", zoomLevel]]; | ||
[self.debugLabel sizeToFit]; | ||
[self setNeedsLayout]; | ||
} | ||
|
||
- (CGSize)intrinsicContentSize { | ||
return CGSizeMake(100, 10); | ||
} | ||
|
||
- (UILabel *)debugLabel { | ||
if (!_debugLabel) { | ||
_debugLabel = [[UILabel alloc] init]; | ||
_debugLabel.font = [UIFont systemFontOfSize:8]; | ||
[self addSubview:_debugLabel]; | ||
} | ||
return _debugLabel; | ||
} | ||
|
||
- (void)layoutSubviews { | ||
[super layoutSubviews]; | ||
|
||
self.debugLabel.frame = CGRectMake(CGRectGetMidX(self.bounds)-CGRectGetMidX(_debugLabel.bounds), | ||
CGRectGetMaxY(self.bounds), | ||
CGRectGetWidth(_debugLabel.frame), | ||
CGRectGetHeight(_debugLabel.frame)); | ||
self.backgroundColor = [UIColor blackColor]; | ||
} | ||
|
||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A label means you'd have to manage constraints internal to this view. That may be a good idea, but consider whether it might be easier to override -drawInRect: and use Core Graphics and attributed string drawing methods to accomplish the same effect, since you don't need to worry about line wrapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use -drawInRect: when I want instant rendering instead of default animation between layouts otherwise I prefer -layoutSubviews. Working directly with the views also improves readability but I haven't really decided yet. The logic should be the same so we can switch to Core Graphics if we don't get the expected behavior without much fuss.