In Xcode go to File -> Swift Packages -> Add Package Dependency and paste in the repo’s url: https://github.com/cs4alhaider/ProfilePlaceholderView
Usage
import ProfilePlaceholderView
Then add .withProfilePlaceholderView( ... ) under Image like:
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)
}
}
}
or, if you don’t want to use any image and you just need a placeholder, then do this:
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)
}
}
}
ProfilePlaceholderView
Add profile placeholder when there is no image 😎
Example Contacts app
Installation
In Xcode go to
File -> Swift Packages -> Add Package Dependency
and paste in the repo’s url:https://github.com/cs4alhaider/ProfilePlaceholderView
Usage
Then add
.withProfilePlaceholderView( ... )
underImage
like:or, if you don’t want to use any image and you just need a placeholder, then do this:
Check the Example project for more details
Author
Abdullah Alhaider, cs.alhaider@gmail.com
License
This project is under the MIT license. See the LICENSE file for more info.