Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created June 26, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prafullakumar/fc6a04ba2323771da5b6a0a4acf6d89f to your computer and use it in GitHub Desktop.
Save prafullakumar/fc6a04ba2323771da5b6a0a4acf6d89f to your computer and use it in GitHub Desktop.
import SwiftUI
struct Chips: View {
let systemImage: String //pass system image
let titleKey: LocalizedStringKey //text or localisation value
@State var isSelected: Bool
var body: some View {
HStack {
Image.init(systemName: systemImage).font(.title3)
Text(titleKey).font(.title3).lineLimit(1)
}.padding(.all, 10)
.foregroundColor(isSelected ? .white : .blue)
.background(isSelected ? Color.blue : Color.white) //different UI for selected and not selected view
.cornerRadius(40) //rounded Corner
.overlay(
RoundedRectangle(cornerRadius: 40)
.stroke(Color.blue, lineWidth: 1.5)
).onTapGesture {
isSelected.toggle() // toggle select - not selected
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment