久久久久久久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 初始化程序?)
主站蜘蛛池模板: 精品一区二区免费视频 | 国产1区2区3区 | 99精品视频一区二区三区 | 国产精品福利视频 | 国产精品视屏 | 久久久九九 | 欧美一级淫片免费视频黄 | 黄色网址在线免费播放 | 青青草一区二区 | 久久精品国产一区二区电影 | 亚洲欧美激情国产综合久久久 | 久草在线影 | 一级免费黄色 | 亚洲视频观看 | 国产精品视频在线观看 | 日本三级网址 | 国产一区二区av | 福利一区二区在线 | 玖玖在线免费视频 | 欧美成人综合 | 性欧美精品一区二区三区在线播放 | 日韩aⅴ在线观看 | 亚洲成人www | 国产一区二区三区四区 | 日本高清在线一区 | 欧美综合国产精品久久丁香 | 韩日免费视频 | www精品美女久久久tv | 97精品国产97久久久久久免费 | 罗宾被扒开腿做同人网站 | 成人深夜福利 | 国产欧美在线 | 99久久亚洲 | 日本一区二区三区在线观看 | 亚洲一区中文字幕在线观看 | 一区二区三区不卡视频 | 超碰免费在线观看 | 日韩三级电影一区二区 | 欧美精品在线观看 | 日韩av最新网址 | 成人精品鲁一区一区二区 |