2017-09-13 3 views
3

텍스트 필드를 탭하기 전까지는 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

네,이 문제도 있습니다. 상쾌한 텍스트로 답변 해 주셔서 감사합니다. –

답변

4

시도해보십시오.

#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 텍스트를 다시 설정합니다.