2014-09-22 42 views
0
//sample problem 
myInputTextBox.layer.borderColor= CFBridgingRetain([UIColor grayColor]); //not working 
myInputTextBox.layer.borderColor= [UIColor grayColor];   //implicit conversion, not working 
myInputTextBox.layer.borderColor= (__bridge CGColorRef)([UIColor grayColor]);//not working 

我花了很多時間。應用程序,myInputTextBox是UITextField對象。請幫我在Xcode中解決這個問題的IOStextInputBox.layer.borderColor不能從代碼中工作

//Actual code is 
UITextField *_PI[6]; 
for(int i=0;i<totalChances;i++){ 
    _PI[i]=[[UITextField alloc] initWithFrame:CGRectOffset(CGRectMake(15,55, 50,30), 49*i,0)]; 
    _PI[i].placeholder=[NSString stringWithFormat:@"P(%c)",(i+'A')]; 
    _PI[i].Delegate=self; 
    _PI[i].font=fontInputs; 
    _PI[i].borderStyle=UITextBorderStyleLine; 
    _PI[i].layer.borderWidth=0.5f;//even if i change the border width to 2.0, it does not work 
    _PI[i].layer.borderColor= (__bridge CGColorRef)([UIColor grayColor]);//this line doesn't works 
    [self.view addSubview:_PI[i]]; 
} 
+0

做你檢查myInputTextBox綁定到UI中的任何對象? – Saad 2014-09-22 21:07:04

+0

不,它不是。這是綁定的問題嗎?其實我不知道什麼是綁定。 – Keshab 2014-09-22 21:09:24

+0

你確定它是IBOUtlet? – Saad 2014-09-22 21:10:08

回答

2

嘗試設置邊框寬度

myInputTextBox.layer.borderWidth = 2.0f; 

編輯:

修改代碼爲:

UITextField *_PI[6]; 
    for(int i=0;i<totalChances;i++){ 
     _PI[i]=[[UITextField alloc] initWithFrame:CGRectOffset(CGRectMake(15,55, 50,30), 49*i,0)]; 
     _PI[i].placeholder=[NSString stringWithFormat:@"P(%c)",(i+'A')]; 
     _PI[i].delegate=self; // you had 'd' capital 
     _PI[i].font=fontInputs; 
     _PI[i].borderStyle=UITextBorderStyleLine; 
     _PI[i].layer.borderWidth=5.5f;//even if i change the border width to 2.0, it does not work 
     _PI[i].layer.borderColor= [UIColor grayColor].CGColor;//this line doesn't works 
     [self.view addSubview:_PI[i]]; 
    } 
+0

我已經使用myInputTextBox.layer.borderWidth = 0.5f;讓我檢查這是否是我的問題 – Keshab 2014-09-22 21:10:57

+0

我將寬度一次改爲2.0,一次改爲2.0f。沒有一個工作。 – Keshab 2014-09-22 21:22:32

+0

無法正常工作。沒有用。只是黑色的顏色框只有 – Keshab 2014-09-23 03:42:56