Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


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 Square instead of bar/line), so i placed a UITextField for Text but i don't understand how to change the size of that blinking line/bar.

So, is it possible to change the size of line/bar? and if Yes then how to do it? i know how to change the color of that line/bar but this is something different.

like image 862
Vatsal Shukla Avatar asked Apr 23 '18 05:04

Vatsal Shukla


People also ask

What is Uitextfield?

An object that displays an editable text area in your interface.

How can I increase my cursor height in flutter?

After searching everywhere I finally found it you have to give style: TextStyle( height: 2.0, ), to increase the cursor height.


2 Answers

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.

like image 127
Kamran Avatar answered Oct 21 '22 18:10

Kamran


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

like image 1
Naresh Avatar answered Oct 21 '22 17:10

Naresh