2011-03-09 123 views
1

我创建了一个的UITextField编程用下面的代码:的UITextField黑色像素的边缘是

self._maxPriceField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, labelWidth, labelHeight)]; 
self._maxPriceField.borderStyle  = UITextBorderStyleRoundedRect; 
self._maxPriceField.clearButtonMode = UITextFieldViewModeWhileEditing; 
self._maxPriceField.font   = fieldFont; 
self._maxPriceField.delegate  = self; 

我遇到的问题是,我的UITextField结束有边缘上的这些奇怪的黑色像素。这发生在设备和模拟器上。您可以在下面的截图中看到:

当我创建使用IB相同的UITextField,具有相同的规格和背景,我没有问题。不幸的是我需要以编程方式创建这个UITextField。

以前有人看过这个吗?该怎么办?

You can see the black pixels at the edge of the UITextField here, right in the middle of the left edge.

回答

3

看来这是文本框在屏幕上绘制方式。我玩了一下你的代码,如果我将文本字段高度设置为低于20左右,就会看到明显不正确的明显“阴影”。

我的建议是要么使用20或更高的高度文本字段,或使用不同的风格,如挡板或线和背景设置为白色。

这里是演示截图: enter image description here

这里是我用来绘制这些代码:

int labelWidth = 100; 
int labelHeight = 10; 

_maxPriceField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, labelWidth, labelHeight)]; 
_maxPriceField.borderStyle  = UITextBorderStyleRoundedRect; 
_maxPriceField.clearButtonMode = UITextFieldViewModeWhileEditing; 

//_maxPriceField.font   = fieldFont; 
//_maxPriceField.delegate  = self; 
[self.view addSubview:_maxPriceField]; 

UITextField *secondField = [[UITextField alloc] initWithFrame:CGRectMake(10, 40, labelWidth, labelHeight + 10)]; 
secondField.borderStyle  = UITextBorderStyleRoundedRect; 
[self.view addSubview:secondField]; 
[secondField release]; 

UITextField *thirdField = [[UITextField alloc] initWithFrame:CGRectMake(10, 70, labelWidth, labelHeight + 20)]; 
thirdField.borderStyle  = UITextBorderStyleRoundedRect; 
[self.view addSubview:thirdField]; 
[thirdField release]; 

UITextField *fourthField = [[UITextField alloc] initWithFrame:CGRectMake(10, 110, labelWidth, labelHeight + 30)]; 
fourthField.borderStyle  = UITextBorderStyleRoundedRect; 
[self.view addSubview:fourthField]; 
[fourthField release]; 

UITextField *noRoundFirst = [[UITextField alloc] initWithFrame:CGRectMake(10, 160, labelWidth, labelHeight)]; 
noRoundFirst.borderStyle = UITextBorderStyleBezel; 
noRoundFirst.backgroundColor = [UIColor whiteColor]; 
[self.view addSubview:noRoundFirst]; 
[noRoundFirst release]; 

希望这有助于。

的Mk