Hi. I found this info on Expanding Lists super helpful!
https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-expanding-lists
But I need to assistance on how/if I can format certain elements of the list. Here's the code from the page above.
struct Bookmark: Identifiable {
let id = UUID()
let name: String
let icon: String
var items: [Bookmark]?
// some example websites
static let apple = Bookmark(name: "Apple", icon: "1.circle")
static let bbc = Bookmark(name: "BBC", icon: "square.and.pencil")
static let swift = Bookmark(name: "Swift", icon: "bolt.fill")
static let twitter = Bookmark(name: "Twitter", icon: "mic")
// some example groups
static let example1 = Bookmark(name: "Favorites", icon: "star", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
static let example2 = Bookmark(name: "Recent", icon: "timer", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
static let example3 = Bookmark(name: "Recommended", icon: "hand.thumbsup", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
}
struct ContentView: View {
let items: [Bookmark] = [.example1, .example2, .example3]
var body: some View {
List(items, children: \.items) { row in
HStack {
Image(systemName: row.icon)
Text(row.name)
}
}
}
}
Here's what I would like to do
- I would like to 'star' icon and the 'favorites' to be of a specified color.
- I would like the list elements, Apple, BBC etc.... to be of a specified color (which may be different to 1 above).
Any advice, is this possible?
Thank you for any advice!!
edit: I might also want the 'favorites' to use a different font to the items in the list. :)