White text in UITextField = Invisible text in iPhone copy and paste application. Fix?

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

Any way to fix this?

+3
source share
5 answers

Of course! The background color of the magnifier always matches the property of the backgroundColortext field. (But not a property background.) Example:

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

If your text field absolutely needs a transparent background, you will have to fake it - using a background image containing graphics under the text field. You can do this manually - by taking a screenshot of your interface and cropping it or programmatically, for example:

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

, , .

+4

, . , iPhone OS-white text . , - Apple.

+1

textView.backgroundColor. , :

@interface FakeBgTextView : UITextView {
    UIColor *_fakeBackgroundColor;
}

- (UIColor *)backgroundColor;
- (void)setFakeBackgroundColor:(UIColor *)color;
@end

@implementation FakeBgTextView
...
- (UIColor *)backgroundColor {
    return _fakeBackgroundColor;
}

- (void)setFakeBackgroundColor:(UIColor *)color {
    [_fakeBackgroundColor release];
    _fakeBackgroundColor = [color retain];
}
...
@end
+1

, , iOS5 , . .

+1

, , , ( ) , .

, , .

, didBeginEditing, didEndEditing.

Only one other possible approach and one that I have used in several applications.

eg.

- (void)textFieldDidBeginEditing:(UITextField *)textField {
  textField.textColor = [UIColor colorWithRed:116.0/255.0 green:160.0/255.0 blue:246.0/255.0 alpha:1.0];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
  textField.textColor = [UIColor colorWithRed:224.0/255.0 green:224.0/255.0 blue:224.0/255.0 alpha:1.0];
}
0
source

Source: https://habr.com/ru/post/1710186/


All Articles