Custom TextField in SwiftUI
Corner Radius and Shadow
Code:
CustomTextField.swift
import SwiftUI
struct CapsuleTextField: View {
@State var placeholder: String
@State var value: String
@State var leftIcone: Image? = nil
var body: some View {
HStack {
if leftIcone != nil{
self.leftIcone!
.resizable()
.renderingMode(.original)
.scaledToFit()
.frame(width: 25, height: 25)
.padding(.leading, 20)
}
TextField(self.placeholder, text: $value)
.frame(height: 55)
.foregroundColor(Color(red: 1/255, green: 1/255, blue: 60/255))
}
.background(Color.white)
.clipShape(Capsule())
.shadow(radius: 4, x: 0, y: 3)
}
}
struct CapsuleTextField_Previews: PreviewProvider {
static var previews: some View {
CapsuleTextField(placeholder: "placeholder", value: "value")
}
}
To use this textfield write following line of code:
CapsuleTextField(placeholder:"Email",value:self.email)
No comments:
Post a Comment