Swiftui 圆角边框
时间: 2023-12-14 08:34:44 浏览: 40
以下是在SwiftUI中实现圆角边框的方法:
```swift
Button("Button with rounded border") {
// 按钮被点击时执行的代码
}
.padding()
.background(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.orange, lineWidth: 2)
)
```
在这个例子中,我们使用了`RoundedRectangle`来创建一个圆角矩形,然后使用`.stroke`方法来设置边框的颜色和宽度。最后,我们将这个圆角矩形作为按钮的背景。
如果您想要同时设置圆角和边框,可以像下面这样使用`.border`和`.cornerRadius`方法:
```swift
Button("Button with rounded border and corner radius") {
// 按钮被点击时执行的代码
}
.padding()
.border(Color.orange, width: 2)
.cornerRadius(20)
```
在这个例子中,我们首先使用`.border`方法来设置边框的颜色和宽度,然后使用`.cornerRadius`方法来设置圆角的半径。
相关问题
swiftui Button 蓝色圆角按钮
您可以使用以下代码创建一个蓝色圆角按钮:
```swift
Button(action: {
// 按钮被点击时执行的操作
}) {
Text("按钮标题")
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
```
这个代码会创建一个蓝色背景、白色文本、圆角为 10 的按钮。您可以根据需要调整按钮的颜色和圆角大小。
SwiftUI 学习网站
以下是一些学习SwiftUI的网站:
1. SwiftUI官方文档:https://developer.apple.com/documentation/swiftui
2. Ray Wenderlich:https://www.raywenderlich.com/tags/swiftui
3. Hacking with Swift:https://www.hackingwithswift.com/articles/216/what-is-swiftui
4. Swift with Majid:https://swiftwithmajid.com/
5. SwiftUI Tutorials:https://www.appcoda.com/swiftui-tutorials/
6. SwiftLee:https://www.avanderlee.com/category/swift/swiftui/
7. SwiftUI Lab:https://swiftui-lab.com/
8. Swift UI Hub:https://swiftuihub.com/
这些网站都提供了丰富的SwiftUI学习资源,包括教程、文章、视频等,你可以根据需要选择适合自己的学习方式。同时,也可以通过搜索引擎找到更多的SwiftUI学习资源。希望这些网站能够帮助你学习SwiftUI。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)