自定义UITextField,图像作为背景闪烁光标问题 [英] custom UITextField with image as a background blinking cursor issue

查看:126
本文介绍了自定义UITextField,图像作为背景闪烁光标问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以UIImage为背景的自定义UITextField。现在,当我在这个UITextField中键入文本并且光标闪烁时,我得到这个:

I have a custom UITextField with a UIImage as a background. Now when I type in a text into this UITextField and the cursor is blinking I get this:

我不希望光标上的白色图像眨眼,因为它会破坏美学。
我尝试过玩这个并尝试将背景视图设置为与图像颜色相同,但问题是UITextField形状始终是一个矩形。我该如何解决这个问题?

I don't want to have a white image on the cursor blinking as it destroys the aesthetics. I tried playing around with this and tried setting the background view to have the same color as the image, however the issue is that the UITextField shape is always a rectangle. How do I solve this?

推荐答案

您是否尝试过设置 textField.backgroundColor = [UIColor clearColor]

您可以使用UIImageView作为图像,然后将UITextField添加为具有清晰背景的子视图。只需以编程方式或在IB中创建 UIImageView * imageView UITextField * textField 。如果您以编程方式进行,请使用 [imageView addSubview:textField]; 并根据需要设置框架。在IB中,只需将 textField 放到 imageView 上,然后根据需要对齐它。

You can use a UIImageView for the image and then add a UITextField as a subview with clear background. Just create UIImageView *imageView and UITextField *textField, either programmatically or in the IB. If you go programmatically, use [imageView addSubview:textField]; and set the frame as you like. In the IB, just drop the textField onto the imageView and align it as you like.

这篇关于自定义UITextField,图像作为背景闪烁光标问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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