[英]UITextField Black Pixels at Edges
我使用以下代碼以編程方式創建了一個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。
有人看過嗎? 該怎么辦?
似乎這是在屏幕上繪制文本字段的方式。 我稍微玩了一下您的代碼,如果我將文本字段的高度設置為低於20左右,您會開始看到明顯的“陰影”,顯然沒有正確繪制。
我的建議是為文本字段使用20或更高的高度,或者使用其他樣式(例如“邊框”或“線條”)並將背景設置為白色。
這是演示的屏幕截圖:
這是我用來繪制這些代碼的代碼:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.