How to change the size of blinking bar/line for specific UITextField?

前端 未结 3 1655
走了就别回头了
走了就别回头了 2021-01-14 02:10


i\'m working on a project(Swift4,Xcode 9.2) which has a feature to get text input and the blinking bar/line should be of big size (it should be S

相关标签:
3条回答
  • 2021-01-14 02:55

    You can change the size by overriding the frame method for cursor as follows,

    class CustomTextField: UITextField {
    
        override func caretRect(for position: UITextPosition) -> CGRect {
            var rect = super.caretRect(for: position)
            let size = CGSize(width: 10, height: 50)
            // Calculating center y
            let y = rect.origin.y - (size.height - rect.size.height)/2
            rect = CGRect(origin: CGPoint(x: rect.origin.x, y: y), size: size)
            return rect
        }
    }
    

    Set CustomTextField class in xib/storyboard identity inspector for that textField.

    0 讨论(0)
  • 2021-01-14 03:00

    There are some unnecessary lines of codes, so this is the revised:

    class CustomTextField: UITextField {
        override func caretRect(for position: UITextPosition) -> CGRect {
            var rect = super.caretRect(for: position)
            rect = CGRect(x: rect.origin.x, y: .zero, width: 15, height: 30)
            return rect
        }
    }
    
    0 讨论(0)
  • 2021-01-14 03:15

    We can't change the cursor height, but we can do some trick, select your textfield and change your textfield border style as UITextBorderStyleNone

    Check the below link which is already given answer

    there after increase the font size of your textfield whatever you want, then you get the output as

    0 讨论(0)
提交回复
热议问题