Add bottom line to view in SwiftUI / Swift / Objective-C / Xamarin

前端 未结 22 2360
自闭症患者
自闭症患者 2020-11-27 09:19

I would like to keep the border at the bottom part only in UITextField. But I don\'t know how we can keep it on the bottom side.

Can you please advise m

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 09:39

    In SwiftUI, The simplest implementation would be,

    struct MyTextField: View {
      var myPlaceHolder: String
      @Binding var text: String
    
      var underColor: Color
      var height: CGFloat
    
      var body: some View {
        VStack {
            TextField(self.myPlaceHolder, text: $text)
            .padding(.horizontal, 24)
            .font(.title)
    
            Rectangle().frame(height: self.height)
                .padding(.horizontal, 24).foregroundColor(self.underColor)
        }
      }
    }
    

    Usage:

    MyTextField(myPlaceHolder: "PlaceHolder", text: self.$text, underColor: .red, height: 3)
    

提交回复
热议问题