sal*_*000 6 localization ios swift swiftui
我制作了一个 SemiRoundedRectangle 形状,用于对侧面菜单进行 ClipShape。如果用户使用 RTL 语言,我需要翻转它,但不确定实现此目的的最佳方法。
\n我已经尝试过.flipsForRightToLeftLayoutDirection(true),但这也会翻转实际的阿拉伯文本。当我尝试旋转形状时,它不再符合形状协议,因此我不能再在.clipShape. 当我切换到阿拉伯语时,SwiftUI 中的其他所有内容都会神奇地自行翻转,是否可以在我的形状中添加一些东西来赋予它这些魔力?
感谢您的帮助 :)
\n\nimport SwiftUI\n\nstruct SemiRoundedRectangle: Shape {\n var cornerRadius: CGFloat\n func path(in rect: CGRect) -> Path {\n var path = Path()\n path.move(to: CGPoint(x: rect.maxX, y: rect.minY))\n path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))\n path.addLine(to: CGPoint(x: rect.minX+cornerRadius, y: rect.maxY))\n path.addArc(center: CGPoint(x: cornerRadius, y: rect.height - cornerRadius),\n radius: cornerRadius,\n startAngle: .degrees(90),\n endAngle: .degrees(180), clockwise: false)\n path.addLine(to: CGPoint(x: 0, y: cornerRadius))\n path.addArc(center: CGPoint(x: cornerRadius, y: cornerRadius),\n radius: cornerRadius,\n startAngle: .degrees(180),\n endAngle: .degrees(270), clockwise: false)\n path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))\n \n return path\n }\n\n}\n\nstruct TestView {\n var body: some View {\n HStack {\n Text("\xd8\xa7\xd9\x8a\xd9\x87 \xd8\xa7\xd9\x84\xd8\xa3\xd8\xae\xd8\xa8\xd8\xa7\xd8\xb1\xd8\x9f")\n .padding()\n .background(Color.green)\n .clipShape(SemiRoundedRectangle(cornerRadius: 10.0))\n \n Spacer()\n }\n \n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
尝试将 附加clipShape到Color.green:
struct TestView: View {\n var body: some View {\n HStack {\n Text("\xd8\xa7\xd9\x8a\xd9\x87 \xd8\xa7\xd9\x84\xd8\xa3\xd8\xae\xd8\xa8\xd8\xa7\xd8\xb1\xd8\x9f")\n .padding()\n .background(\n Color.green /// here!\n .clipShape(SemiRoundedRectangle(cornerRadius: 10.0))\n .flipsForRightToLeftLayoutDirection(true)\n )\n \n Spacer()\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n结果:
\n| 归档时间: |
|
| 查看次数: |
1081 次 |
| 最近记录: |