如何更改特定UITextField的闪烁条/行的大小? [英] How to change the size of blinking bar/line for specific UITextField?

查看:125
本文介绍了如何更改特定UITextField的闪烁条/行的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在做一个项目(Swift4,Xcode 9.2),该项目具有获取文本输入的功能,并且闪烁的条/线应该是大尺寸的 (it should be Square instead of bar/line) ,所以我为文本放置了一个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.

推荐答案

您可以通过overriding cursorframe方法更改大小,如下所示,

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
    }
}

xib/storyboard身份检查器中为该textField设置CustomTextField类.

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

这篇关于如何更改特定UITextField的闪烁条/行的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆