久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UITextField - iPad 上的 UIKeyboardTypeDecimalPad?

UITextField - UIKeyboardTypeDecimalPad on iPad?(UITextField - iPad 上的 UIKeyboardTypeDecimalPad?)
本文介紹了UITextField - iPad 上的 UIKeyboardTypeDecimalPad?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 iPad 上...

On the iPad...

textField.keyboardType = UIKeyboardTypeDecimalPad;

...只顯示常規鍵盤,但從頂部的數字開始(下面有很多標點符號).

...just shows the regular keyboard, but starting on the numbers at the top (with lots of punctuation underneath).

但它是輸入一個數字.我只希望用戶能夠鍵入數字和小數點,就像 iPhone 上的 UIKeyboardTypeDecimalPad 一樣.

But it's to type in a number. I only want the users to be able to type numbers and a decimal point, like UIKeyboardTypeDecimalPad does on the iPhone.

有什么方法可以讓不相關的鍵消失并讓我的用戶獨自一人?

Is there any way to make the irrelevant keys go away and leave my user alone?

推薦答案

設置 UITextFieldkeyboardType 只會讓用戶更容易輸入適當的字符.即使在 iPhone 上,用戶也可以通過硬件鍵盤或粘貼字符串來輸入其他字符.

Setting a UITextField's keyboardType only makes it easier for a user to enter appropriate characters. Even on the iPhone, users can enter other characters via a hardware keyboard, or by pasting in a string.

改為實現 UITextFieldDelegate-textField:shouldChangeCharactersInRange:replacementString: 來驗證用戶輸入.您也可能真的不想硬編碼數字 0-9 和句點.例如,某些語言環境中的用戶使用逗號將整數與小數分開:

Instead, implement UITextFieldDelegate's -textField:shouldChangeCharactersInRange:replacementString: to validate user input. You also probably don't really want to hardcode the digits 0-9 and a period. Users in some locales, for example, separate whole numbers from decimals with a comma:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *candidate = [[textField text] stringByReplacingCharactersInRange:range withString:string];
    if (!candidate || [candidate length] < 1 || [candidate isEqualToString:@""])
    {
        return YES;
    }
    NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:candidate];
    if (!number || [number isEqualToNumber:[NSDecimalNumber notANumber]])
    {
        return NO;
    }
    return YES;
}

或者,您可以在用戶完成輸入文本時執行驗證,在 –textFieldShouldReturn:–textFieldShouldEndEditing:–textFieldDidEndEditing: 中根據需要.

Alternately, you might perform validation when the user finishes entering text, in –textFieldShouldReturn:, – textFieldShouldEndEditing:, or – textFieldDidEndEditing: as desired.

這篇關于UITextField - iPad 上的 UIKeyboardTypeDecimalPad?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw stars using Quartz Core?(如何使用 Quartz Core 繪制星星?)
Why does giving addArcWithCenter a startAngle of 0 degrees make it start at 90 degrees?(為什么給 addArcWithCenter 一個 0 度的 startAngle 使它從 90 度開始?)
Find the CGPoint on a UIView rectangle intersected by a straight line at a given angle from the center point(在與中心點成給定角度的直線相交的 UIView 矩形上找到 CGPoint)
Which is the best way to estimate measure of photographed things?(哪種方法是估計拍攝物體尺寸的最佳方法?)
How to convert an Int to a Character in Swift(如何在 Swift 中將 Int 轉換為字符)
How to create a hex color string UIColor initializer in Swift?(如何在 Swift 中創建十六進制顏色字符串 UIColor 初始化程序?)
主站蜘蛛池模板: 日韩精品视频在线 | 97视频成人| 久久青青 | 91精品国产综合久久精品 | 久久99精品久久久久久 | 中文字幕在线观看成人 | 精品视频在线一区 | 精品国产一区二区三区久久 | 九九亚洲 | av日韩在线播放 | 亚洲欧洲小视频 | 欧美成人精品在线 | 国产在线一区二区 | 国产综合精品 | 亚洲精品日韩在线 | 在线免费观看黄色 | 亚洲综合在线视频 | av网站在线看 | www.色五月.com | 亚洲欧美一区二区三区国产精品 | 亭亭五月激情 | 国产成人免费在线观看 | 亚洲经典一区 | 国产一区999 | 午夜欧美日韩 | 天天干精品 | 久久机热 | 国产精品精品视频一区二区三区 | 亚洲午夜视频 | 亚洲精品在线免费看 | wwwxxx国产| 亚洲欧洲成人av每日更新 | 日本国产高清 | 在线亚洲一区二区 | 午夜免费精品视频 | 中文字幕亚洲精品在线观看 | 亚洲欧美日韩在线一区二区 | 91久久视频 | 午夜精品视频在线观看 | 久久小视频 | 视频一区二区三区中文字幕 |