【发布时间】:2013-09-12 01:22:37
【问题描述】:
我真的很喜欢 iOS 7 中后退按钮箭头的形状,并且想在我的一个 UIButtons 上使用它,但我喜欢 > 而不是
【问题讨论】:
-
完美地绘制它要容易得多 - 这个函数非常简单,我把它放在一个答案中。完美搭配。
标签: iphone ios uibutton interface-builder
我真的很喜欢 iOS 7 中后退按钮箭头的形状,并且想在我的一个 UIButtons 上使用它,但我喜欢 > 而不是
【问题讨论】:
标签: iphone ios uibutton interface-builder
【讨论】:
chevron.backward。
您可以使用 Cédric Luthi 在 GitHub 上的 iOS-Artwork-Extractor 提取所有 iOS7 艺术作品:在模拟器中编译此应用并查找 UINavigationBarBackDefault.png。
图片是。
另一种方法是获取Teehan + Lax iOS7 GUI PSD (iPhone) 文件。它包含大部分 iOS7 艺术品。还有一个Sketch App 版本:Teehan + Lax iOS7 GUI for Sketch。
【讨论】:
Apple 官方后退按钮符号图稿可在以下网址下载 https://developer.apple.com/ios/human-interface-guidelines/resources/
【讨论】:
我的解决方案是使用 Unicode 字符作为后退按钮图标:
‹
左单引号 Unicode:U+2039,UTF-8:E2 80 B9
HTML 实体:‹
缺点:
优点:
说明:
也许还有更好的字符,看起来像后退按钮图标...
【讨论】:
复制粘贴。
使视图 32 x 32。
对于位置,iOS 常用位置是距离左侧安全区 24 处。
@IBDesignable class BackArrow32Button: UIButton {
override func draw(_ rect: CGRect) {
//
// this is just carefully MATCHED to the Apple one (2019)
// make the box > 32x32 < and have it > 24 on the left from safe area <
//
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 17, y: 6))
bezierPath.addLine(to: CGPoint(x: 7, y: 16))
bezierPath.addLine(to: CGPoint(x: 17, y: 26))
UIColor.black.setStroke()
bezierPath.lineWidth = 3
bezierPath.stroke()
}
}
一个细节...
我没有添加内在内容大小,因为,
(A) 对于像这样的新程序员来说可能更容易
(B) 一般来说,固有尺寸只是在界面构建器上被破坏了,所以为了简单的生活,你最好只输入带有约束的高度和宽度:/
【讨论】:
从 iOS 14 开始,这是一个名为 chevron.backward 的系统映像。您可以从 Interface Builder 中的图像下拉菜单中选择它,或以编程方式使用 UIImage(named: "chevron.backward")
由于某种原因,这似乎已从 iOS 13 中的 chevron.left 重命名,因此如果您需要向后兼容,请改用那个。
令人讨厌的是,如果您希望进一步向后兼容,您仍然需要在资产目录中提供具有相同名称的备用图像。此处的其他答案已经涵盖了这种可能性,但请注意,背面 V 形已更改了几次,因此您可能需要确保所提供的图像在使用之前仍然是最新的。
【讨论】:
我想回答这个问题:
Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar
(受 machoota 那里的回答启发),但它被锁定了,而且,作为新的,我没有代表......无论如何,swiftui 版本:
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
}
}
这是一个肮脏的 hack,但话又说回来,尝试在 swiftui 中远程自定义任何事情现在都感觉很 hacky ...
【讨论】:
这最好通过使用图像来实现。文本无法做到这一点,抱歉。
我找到了this image,它是.png
【讨论】: