Skip to content

Instantly share code, notes, and snippets.

@roddymunro
Created July 13, 2023 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roddymunro/277c560c7dc0de86a4437e8f7c422d88 to your computer and use it in GitHub Desktop.
Save roddymunro/277c560c7dc0de86a4437e8f7c422d88 to your computer and use it in GitHub Desktop.
watchOS cell background
struct ListsView: View {
var body: some View {
List(selection: $selectedList) {
ForEach(lists) { list in
Button(action: { }) {
ListButtonLabel(list: list)
}
.buttonStyle(.plain)
.listRowInsets(EdgeInsets())
}
}
.listStyle(.carousel)
}
}
struct ListButtonLabel: View {
var body: some View {
Text(list.name)
.padding()
.background {
Image(uiImage: list.image)
.resizable()
.scaleEffect(1.02) // to prevent the slight white line from appearing
.scaledToFill()
.frame(minWidth: 0, maxWidth: .infinity)
.frame(minHeight: 0, maxHeight: .infinity)
.aspectRatio(1.66, contentMode: .fill)
.clipShape(RoundedRectangle(cornerRadius: 16))
.contentShape(RoundedRectangle(cornerRadius: 16))
.overlay {
RoundedRectangle(cornerRadius: 16)
.fill(Color.black.opacity(0.3))
}
}
.aspectRatio(1.66, contentMode: .fill)
.contentShape(RoundedRectangle(cornerRadius: 16))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment