我在應用程序上創建,我需要輸入價格。客戶端需要自己的設計鍵盤,所以我開發下面的鍵盤。它工作完美。問題是當文字大於UITextField
時,那麼它顯示點。我搜索谷歌和SO但沒有發現任何東西。
how to avoid dots next to a uitextfield
How to remove dots in UITextfield?和其他的答案,但在我的情況下不能正常工作。 當我用默認的鍵盤它滾動文本我輸入的號碼從UITextField刪除點
我的鍵盤是
時長度大於TextFied寬度則顯示什麼
我的代碼是
- (IBAction)numberPressed:(id)sender {
UIButton *btn=(UIButton *)sender;
int number=btn.tag;
if (number <= 9)
txtPrice.text = [NSString stringWithFormat:@"%@%d",txtPrice.text, number];
//decimal point
else if (number == 10) {
if ([txtPrice.text rangeOfString:@"."].location == NSNotFound)
txtPrice.text = [NSString stringWithFormat:@"%@.", txtPrice.text];
}
//0
else if (number == 11)
txtPrice.text = [NSString stringWithFormat:@"%@0", txtPrice.text];
//backspace
else if (number == 12) {
if ([txtPrice.text length] > 0)
txtPrice.text = [txtPrice.text substringToIndex:[txtPrice.text length] - 1];
else
txtPrice.text = @"";
}
}
#pragma mark -
#pragma mark -TextField Delegate Method
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self showKeyboard];
return NO; // Hide both keyboard and blinking cursor.
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return YES;
}
你使用'UITextField'還是'UILabel'?當UILabel變得太長時,它會自動截斷它的內容。 – Greg
你想讓它顯示什麼? – kushyar
@PartiallyFinite感謝您的重播,我用UITextField –