gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:35:39 27 4
gpt4 key购买 nike

如果我的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com