2011-03-09 122 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