Skip to content

Instantly share code, notes, and snippets.

@mahmudahsan
Created March 26, 2020 10:48
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 mahmudahsan/0f8d448b437d63769ef7fad5569af945 to your computer and use it in GitHub Desktop.
Save mahmudahsan/0f8d448b437d63769ef7fad5569af945 to your computer and use it in GitHub Desktop.
import SwiftUI
//MARK:- Single Radio Button Field
struct RadioButtonField: View {
let id: String
let label: String
let size: CGFloat
let color: Color
let textSize: CGFloat
let isMarked:Bool
let callback: (String)->()
init(
id: String,
label:String,
size: CGFloat = 20,
color: Color = Color.black,
textSize: CGFloat = 14,
isMarked: Bool = false,
callback: @escaping (String)->()
) {
self.id = id
self.label = label
self.size = size
self.color = color
self.textSize = textSize
self.isMarked = isMarked
self.callback = callback
}
var body: some View {
Button(action:{
self.callback(self.id)
}) {
HStack(alignment: .center, spacing: 10) {
Image(systemName: self.isMarked ? "largecircle.fill.circle" : "circle")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: self.size, height: self.size)
Text(label)
.font(Font.system(size: textSize))
Spacer()
}.foregroundColor(self.color)
}
.foregroundColor(Color.white)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment