在没有图像时添加个人资料占位符 😎
联系人列表 | #1. | #2. | #3. |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
需要 iOS 13 和 Xcode 11!
在 Xcode 中,进入 File -> Swift Packages -> Add Package Dependency
并粘贴仓库的 URL:https://github.com/cs4alhaider/ProfilePlaceholderView
import ProfilePlaceholderView
然后在 Image
下添加 .withProfilePlaceholderView( ... )
,例如
struct ContactRow: View {
let contact: Contact
var body: some View {
HStack {
Image(contact.imageString ?? "")
.resizable()
.withProfilePlaceholderView(name: contact.name) // HERE YOU CAN PASS MANY THINGS ALSO
.clipShape(Circle())
.frame(width: 60, height: 60)
Text(contact.name)
.font(.headline)
}
}
}
或者,如果您不想使用任何图像,只需要一个占位符,请这样做
struct ContactRow: View {
let contact: Contact
var body: some View {
HStack {
ProfilePlaceholderView(name: contact.name)
.clipShape(Circle())
.frame(width: 60, height: 60)
Text(contact.name)
.font(.headline)
}
}
}
查看 Example 项目以获取更多详细信息
Abdullah Alhaider, cs.alhaider@gmail.com
此项目基于 MIT 许可证。 详见 LICENSE 文件。