Home > AI > IOS > SwiftUI >

LibraryContentProvider

Example:

struct UserProfileView: View {
    var user: User
    
    var body: some View {
        HStack {
            Image(user.imageName)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 60, height: 60)
                .cornerRadius(30)
                .overlay(
                    RoundedRectangle(cornerRadius: 30)
                        .stroke(Color.white, lineWidth: 3)
                )
            
            VStack(alignment: .leading) {
                Text(user.name)
                    .font(.headline)
                Text(user.handle)
                    .font(.subheadline)
                    .foregroundColor(.gray)
            }
        }
    }
}

struct User {
    let imageName: String
    let name: String
    let handle: String
}



struct UserProfileLibrary: LibraryContentProvider {
    var views: [LibraryItem] {
        let user = User(imageName: "john", name: "John Doe", handle: "@johndoe")
        return [LibraryItem(UserProfileView(user: user), title: "User Profile", category: .control)]
    }
}

Then you can access “User Profile” in the view library.

Leave a Reply