Skip to content

Commit 7ebd9ae

Browse files
author
Jill Cardamon
committed
Initial redesign implementation.
1 parent 4ad5f99 commit 7ebd9ae

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

Sources/MapboxNavigation/Resources/en.lproj/Localizable.strings

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"SLOWER_ALTERNATIVE" = "%@ slower";
255255

256256
/* Label above the speed limit in an MUTCD-style speed limit sign. Keep as short as possible. */
257-
"SPEED_LIMIT_LEGEND" = "Max";
257+
"SPEED_LIMIT_LEGEND" = "Speed Limit";
258258

259259
/* The text of a banner that appears during turn-by-turn navigation when route simulation is enabled. */
260260
"USER_IN_SIMULATION_MODE" = "Simulating Navigation at %@×";

Sources/MapboxNavigation/SpeedLimitStyleKit.swift

+76
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,82 @@ public class SpeedLimitStyleKit : NSObject {
9191

9292
}
9393

94+
@objc dynamic public class func drawMUTCDForUS(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 68, height: 85), resizing: ResizingBehavior = .aspectFit, signBackColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000), strokeColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000), limit: String = "50", legend: String = "SPEED LIMIT") {
95+
//// General Declarations
96+
let context = UIGraphicsGetCurrentContext()!
97+
98+
//// Resize to Target Frame
99+
context.saveGState()
100+
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 68, height: 85), target: targetFrame)
101+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
102+
context.scaleBy(x: resizedFrame.width / 68, y: resizedFrame.height / 85)
103+
104+
105+
106+
//// Variable Declarations
107+
let limitFontSize: CGFloat = CGFloat(limit.count) > 2 ? 24 : 32
108+
109+
//// Sign
110+
//// Sign Back Drawing
111+
let signBackPath = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: 68, height: 80), cornerRadius: 10)
112+
signBackColor.setFill()
113+
signBackPath.fill()
114+
signBackColor.setStroke()
115+
signBackPath.lineWidth = 4
116+
signBackPath.lineJoinStyle = .bevel
117+
signBackPath.stroke()
118+
119+
120+
//// Border Drawing
121+
let borderPath = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: 68, height: 80), cornerRadius: 10)
122+
UIColor.lightGray.setStroke()
123+
borderPath.lineWidth = 3
124+
borderPath.lineJoinStyle = .bevel
125+
borderPath.stroke()
126+
127+
128+
129+
130+
//// Group
131+
//// Limit Label Drawing
132+
let limitLabelRect = CGRect(x: 3, y: 40, width: 68, height: 45)
133+
let limitLabelStyle = NSMutableParagraphStyle()
134+
limitLabelStyle.alignment = .center
135+
let limitLabelFontAttributes = [
136+
.font: UIFont.systemFont(ofSize: limitFontSize, weight: .semibold),
137+
.foregroundColor: strokeColor,
138+
.paragraphStyle: limitLabelStyle,
139+
] as [NSAttributedString.Key: Any]
140+
141+
let limitLabelTextHeight: CGFloat = limit.boundingRect(with: CGSize(width: limitLabelRect.width, height: CGFloat.infinity), options: .usesLineFragmentOrigin, attributes: limitLabelFontAttributes, context: nil).height
142+
context.saveGState()
143+
context.clip(to: limitLabelRect)
144+
limit.draw(in: CGRect(x: limitLabelRect.minX, y: limitLabelRect.minY + (limitLabelRect.height - limitLabelTextHeight) / 2, width: limitLabelRect.width, height: limitLabelTextHeight), withAttributes: limitLabelFontAttributes)
145+
context.restoreGState()
146+
147+
148+
//// Legend Label Drawing
149+
let legendLabelRect = CGRect(x: 3, y: 10, width: 68, height: 37)
150+
let legendLabelStyle = NSMutableParagraphStyle()
151+
legendLabelStyle.alignment = .center
152+
legendLabelStyle.lineSpacing = 0.05
153+
legendLabelStyle.paragraphSpacing = 0.05
154+
let legendLabelFontAttributes = [
155+
.font: UIFont.systemFont(ofSize: UIFont.labelFontSize, weight: .semibold),
156+
.foregroundColor: strokeColor,
157+
.paragraphStyle: legendLabelStyle,
158+
] as [NSAttributedString.Key: Any]
159+
160+
let legendLabelTextHeight: CGFloat = legend.boundingRect(with: CGSize(width: legendLabelRect.width, height: CGFloat.infinity), options: .usesLineFragmentOrigin, attributes: legendLabelFontAttributes, context: nil).height
161+
context.saveGState()
162+
context.clip(to: legendLabelRect)
163+
legend.draw(in: CGRect(x: legendLabelRect.minX, y: legendLabelRect.minY + legendLabelRect.height - legendLabelTextHeight, width: legendLabelRect.width, height: legendLabelTextHeight), withAttributes: legendLabelFontAttributes)
164+
context.restoreGState()
165+
166+
context.restoreGState()
167+
168+
}
169+
94170
@objc dynamic public class func drawVienna(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 70, height: 70), resizing: ResizingBehavior = .aspectFit, signBackColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000), strokeColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000), regulatoryColor: UIColor = UIColor(red: 0.800, green: 0.000, blue: 0.000, alpha: 1.000), limit: String = "50") {
95171
//// General Declarations
96172
let context = UIGraphicsGetCurrentContext()!

Sources/MapboxNavigation/SpeedLimitView.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public class SpeedLimitView: UIView {
9595
return formatter
9696
}()
9797

98+
let locale = Locale.current
99+
98100
override init(frame: CGRect) {
99101
super.init(frame: frame)
100102

@@ -141,8 +143,13 @@ public class SpeedLimitView: UIView {
141143

142144
switch signStandard {
143145
case .mutcd:
144-
let legend = NSLocalizedString("SPEED_LIMIT_LEGEND", bundle: .mapboxNavigation, value: "Max", comment: "Label above the speed limit in an MUTCD-style speed limit sign. Keep as short as possible.").uppercased()
145-
SpeedLimitStyleKit.drawMUTCD(frame: bounds, resizing: .aspectFit, signBackColor: signBackColor, strokeColor: textColor, limit: formattedSpeedLimit, legend: legend)
146+
if locale.identifier == "en_US" {
147+
let legend = NSLocalizedString("SPEED_LIMIT_LEGEND", bundle: .mapboxNavigation, value: "Speed Limit", comment: "Label above the speed limit in an MUTCD-style speed limit sign. Keep as short as possible.").uppercased()
148+
SpeedLimitStyleKit.drawMUTCDForUS(frame: bounds, resizing: .aspectFit, signBackColor: signBackColor, strokeColor: textColor, limit: formattedSpeedLimit, legend: legend)
149+
} else {
150+
let legend = NSLocalizedString("SPEED_LIMIT_LEGEND", bundle: .mapboxNavigation, value: "Max", comment: "Label above the speed limit in an MUTCD-style speed limit sign. Keep as short as possible.").uppercased()
151+
SpeedLimitStyleKit.drawMUTCD(frame: bounds, resizing: .aspectFit, signBackColor: signBackColor, strokeColor: textColor, limit: formattedSpeedLimit, legend: legend)
152+
}
146153
case .viennaConvention:
147154
SpeedLimitStyleKit.drawVienna(frame: bounds, resizing: .aspectFit, signBackColor: signBackColor, strokeColor: textColor, regulatoryColor: regulatoryBorderColor, limit: formattedSpeedLimit)
148155
}

0 commit comments

Comments
 (0)