无法更改iOS 11中的多个文本字体颜色GM

问题描述:

在iOS 10.3模拟器上工作,但不在iOS 11上,直到您点击文本框。无法更改iOS 11中的多个文本字体颜色GM

层次:

view hierarchy

实施例下面的代码。

#import "ViewController.h" 

@interface ViewController() 
@property (nonatomic) UITextField *textField1; 
@property (nonatomic) UITextField *textField2; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 50, 50, 30)]; 
    textField.borderStyle = UITextBorderStyleLine; 
    [self.view addSubview:textField]; 
    self.textField1 = textField; 

    UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 50, 30)]; 
    textField2.borderStyle = UITextBorderStyleLine; 
    [self.view addSubview:textField2]; 
    self.textField2 = textField2; 

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 50, 50)]; 
    button.backgroundColor = [UIColor blueColor]; 
    [button addTarget:self action:@selector(changeColor) forControlEvents:UIControlEventTouchUpInside]; 

    [self.view addSubview:self.textField1]; 
    [self.view addSubview:self.textField2]; 
    [self.view addSubview:button]; 
} 

- (void)changeColor 
{ 
    self.textField1.textColor = [UIColor greenColor]; 
    self.textField2.textColor = [UIColor greenColor]; 
} 
+0

你能澄清你的问题。究竟发生了什么? – rmaddy

+0

我试图在轻按按钮时更改两个UITextFields的文本颜色。只有一个文本字段实际上会更改文本颜色。在图像中的检查员Xcode认为颜色是绿色的(R:0 G:1 B:0),但显示的内容仍然是黑色。我目前在应用商店中有一个应用正在做同样的事情,但在iOS 10中这不会发生。 –

+0

是的,我也有这个问题。清爽的文字答案正在为我工​​作。 –

试试这个。

#import "ViewController.h" 

@interface ViewController() 
@property (nonatomic) UITextField *textField1; 
@property (nonatomic) UITextField *textField2; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 50, 50, 30)]; 
    textField.borderStyle = UITextBorderStyleLine; 
    [self.view addSubview:textField]; 
    self.textField1 = textField; 

    UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 50, 30)]; 
    textField2.borderStyle = UITextBorderStyleLine; 
    [self.view addSubview:textField2]; 
    self.textField2 = textField2; 

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 50, 50)]; 
    button.backgroundColor = [UIColor blueColor]; 
    [button addTarget:self action:@selector(changeColor) forControlEvents:UIControlEventTouchUpInside]; 

    [self.view addSubview:self.textField1]; 
    [self.view addSubview:self.textField2]; 
    [self.view addSubview:button]; 
} 

- (void)changeColor 
{ 
    self.textField1.textColor = [UIColor greenColor]; 
    self.textField2.textColor = [UIColor greenColor]; 
    self.textField1.text = self.textField1.text; 
} 

只是重置textfiled1文本。