2014-09-22 121 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