UITextField中的白色文本= iPhone复制/粘贴选择中的不可见文本。固定? [英] White Text in UITextField = Invisible text in iPhone copy/paste select. Fix?

查看:167
本文介绍了UITextField中的白色文本= iPhone复制/粘贴选择中的不可见文本。固定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的UITextField中有白色文本,则选择窗口(选择文本时)是不可见的,因为小窗口上的背景也是白色。

If I have white text in my UITextField, the selection window (when selecting text) is invisible because the background on the little window is also white.

任何方式解决这个问题?

Any way to fix this?

推荐答案

当然可以!放大镜的背景颜色始终与文本字段的 backgroundColor 属性匹配。 (但不是背景属性。)示例:

Sure! The background color of the loupe always matches the backgroundColor property of the text field. (But not the background property.) Example:

textField.textColor = [UIColor whiteColor];
textField.backgroundColor = [UIColor blackColor];

如果您的文字字段绝对需要透明背景,那么您将拥有通过使用包含文本字段下面的图形的背景图像来伪造它。您可以手动执行此操作 - 通过获取界面的屏幕截图并进行裁剪或以编程方式进行裁剪,如下所示:

If your text field absolutely requires a transparent background, you'll have to fake it—by using a background image containing the graphics underneath the text field. You may do it manually—by taking a screenshot of your interface and cropping it—or programmatically, like this:

#import <QuartzCore/CALayer.h>
...
// `view` contains the graphics underneath the text field
UIGraphicsBeginImageContext(textField.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint origin = [textField convertPoint:textField.bounds.origin toView:view];
CGContextTranslateCTM(context, -origin.x, -origin.y);
[view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
textField.background = image;

由于背景是在背景颜色之上绘制的,因此文本字段将出现透明,你可以使用你想要的任何背景颜色放大镜。

Since the background is drawn on top of the background color, the text field will appear transparent, and you'll be able to use any background color you want for the loupe.

这篇关于UITextField中的白色文本= iPhone复制/粘贴选择中的不可见文本。固定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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