swiftui - 为什么我的按钮只能在选定区域点击?
问题描述
我有一个按钮,但它似乎只能在选定区域中单击。我试过玩框架等,但无济于事。
Button(action: {
print("HELLO")
}){
Text("HELLO")
.foregroundColor(.red)
.font(.title)
.fontWeight(.light)
.frame(width: 300, height: 100, alignment: .center)
.background(Rectangle().stroke(Color.red, lineWidth: 1.0))
}
解决方案
尝试添加 .contentShape 修饰符:
Button(action:, label:)
.contentShape(RoundedRectangle(cornerRadius: 8))
推荐阅读
- python - 将整数数组转换为二进制表示矩阵
- python - AttributeError:“lxml.etree.QName”对象没有属性“resolve”
- azure - Azure CosmosDB 准时触发到有效期限
- cmd - Windows机器上的git-lab-runner中的命令不起作用
- unity3d - 当 AppendStructuredBuffer 在计算着色器中溢出时会发生什么?
- sql - 无法合并 2 个表
- python-3.x - \n 在 Python 3 中的混淆
- python - 如何将 Pandas 列切片转置并插入行切片?
- xml - 如何以与 androidstudio 中相同的大小显示我的按钮和图像视图?
- swift - 如何更改 CAShapeLayer 内的区域?