I really like the shape of the back button arrow in iOS 7, and would like to use it on one of my UIButtons, but like > instead of <. Would there be a way with text, or should
i meant to answer this question:
Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar
(inspired by machoota's answer there), but it's locked, and, being new, i don't have the rep ... anyway, swiftui version:
struct BackArrow: View
{
@Environment(\.horizontalSizeClass) var hsc: UserInterfaceSizeClass?
@Environment(\.verticalSizeClass) var vsc: UserInterfaceSizeClass?
var color: Color
var body: some View {
Path { path in
let height = self.arrowHeight(h: self.hsc, v: self.vsc)
let width = height * 0.6
path.move(to: CGPoint(x: width * 5.0 / 6.0, y: height * 0.0 / 10.0))
path.addLine(to: CGPoint(x: width * 0.0 / 6.0, y: height * 5.0 / 10.0))
path.addLine(to: CGPoint(x: width * 5.0 / 6.0, y: height * 10.0 / 10.0))
path.addQuadCurve( to: CGPoint( x: width * ((6.0 / 6.0) + self.fudgeFactor(h: self.hsc, v: self.vsc)),
y: height * ((9.0 / 10.0) - (self.fudgeFactor(h: self.hsc, v: self.vsc) * 1.666666))),
control: CGPoint( x: width * ((6.0 / 6.0) + self.fudgeFactor(h: self.hsc, v: self.vsc)),
y: height * 10.0 / 10.0))
path.addLine(to: CGPoint( x: width * ((2.0 / 6.0) + (3 * self.fudgeFactor(h: self.hsc, v: self.vsc))),
y: height * 5.0 / 10.0))
path.addLine(to: CGPoint( x: width * ((6.0 / 6.0) + self.fudgeFactor(h: self.hsc, v: self.vsc)),
y: height * ((1.0 / 10.0) + (self.fudgeFactor(h: self.hsc, v: self.vsc) * 1.666666))))
path.addQuadCurve( to: CGPoint( x: width * 5.0 / 6.0,
y: height * 0.0 / 10.0),
control: CGPoint( x: width * ((6.0 / 6.0) + self.fudgeFactor(h: self.hsc, v: self.vsc)),
y: height * 0.0 / 10.0))
}
.fill(color)
.offset(x: -8.0, y: -5.0) // there's probaby some better way to figure this out, but i've wasted too much time already ...
}
private func fudgeFactor(h: UserInterfaceSizeClass?, v: UserInterfaceSizeClass?) -> CGFloat
{ return h == .compact ? ( v == .compact ? 0.01 // (c, c): normal phone, landscape
: 0.003 ) // (c, r): any phone, portrait
: ( v == .compact ? 0.01 // (r, c): large phone, landscape
: 0.003 ) // (r, r): ipad, full-screen, any
}
private func arrowHeight(h: UserInterfaceSizeClass?, v: UserInterfaceSizeClass?) -> CGFloat
{ return h == .compact ? ( v == .compact ? 18.0 // (c, c): normal phone, landscape
: 21.0 ) // (c, r): any phone, portrait
: ( v == .compact ? 18.0 // (r, c): large phone, landscape
: 21.0 ) // (r, r): ipad, full-screen, any
}
}
it's a filthy hack, but then again, trying to do anything remotely custom in swiftui feels pretty hacky right now anyway ...