iphone - UITextField 中的白色文本 = iPhone 复制/粘贴选择中的不可见文本。使固定?

标签 iphone iphone-sdk-3.0

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

有办法解决这个问题吗?

最佳答案

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

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

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

#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;

由于背景是在背景颜色之上绘制的,因此文本字段将显示透明,并且您可以使用放大镜所需的任何背景颜色。

关于iphone - UITextField 中的白色文本 = iPhone 复制/粘贴选择中的不可见文本。使固定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1959512/

相关文章:

iphone - 我可以将 CADisplayLink 用作 NSTimer 吗?

iphone - bundle 显示名称最大长度

iphone - 如何在表格单元格中使用 UIWebView?

jquery - 使用 jQuery touchwipe 默认删除某些删除

iphone - 检查蓝牙状态

iphone - ios应用崩溃

ios - Sqlite数据库,滑动删除

iphone - 我可以更改 UITextView 上自动检测到的链接的颜色吗?

iphone-sdk-3.0 - 通过 SSL HTTPS 从 iPhone 发送 POST 数据

objective-c - 如何在 iPhone SDK 中使用 LinkedIn API?