Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White Text in UITextField = Invisible text in iPhone copy/paste select. Fix?

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?


2 Answers

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.

like image 53
yakovlev Avatar answered Dec 10 '25 00:12

yakovlev


I'm afraid not. The problem's existed since the earliest days of the iPhone OS—white text appears as white-on-white in the cursor-positioning loupe as well. If this is a serious problem for your app, your only real options are to change the text color or to file a radar feature request with Apple.

like image 24
Noah Witherspoon Avatar answered Dec 10 '25 00:12

Noah Witherspoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!