因此,numpad键盘默认没有"完成"或"下一步"按钮,所以我想添加一个.在iOS 6及更低版本中,有一些技巧可以在键盘上添加一个按钮,但它们似乎不适用于iOS 7.
首先,我订阅显示通知的键盘
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
然后我尝试在键盘出现时添加一个按钮:
- (void)keyboardWillShow:(NSNotification *)note
{
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
doneButton.frame = CGRectMake(0, 50, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(dismissKeyboard) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton]; …Run Code Online (Sandbox Code Playgroud) 我正在努力为这个找到答案.我已经找到了如何使用模式字符串[0-9]*使键盘显示在Web应用程序上但只显示没有小数的数字!
有人有解决方案吗?:)
谢谢!
我正在开发一个不是本机iPhone应用程序的移动网站,而是一个简单的m.somedomain.com网站,该网站是在c#asp.net中开发的.
目标:单击其中一个文本框,如何仅显示数字键盘?
注意:该网站不是HTML5,不是Native应用程序内部的Webview的一部分,而是一个独立的常规网站
我的文本框是一个常规的asp.net文本框:
<asp:TextBox runat="server" CssClass="reference_input" Text="1234567" />
Run Code Online (Sandbox Code Playgroud) 我正在撰写一份指令,以验证瑞典社会安全号码(personnummer).要在这样的输入元素上使用:
<input type="text" ng-model="pnr" pnrvalidator />
Run Code Online (Sandbox Code Playgroud)
瑞典社会安全号码的格式为yyyymmdd-nnnn例如19121212-1212
只要我使用,我的指令就可以使用type="text".但由于我希望在移动浏览器上使用数字键盘,然后我改为type="number":
<input type="number" ng-model="pnr" pnrvalidator />
Run Code Online (Sandbox Code Playgroud)
然后我的验证器只有在我的输入中没有输入破折号( - )时才有效,例如191212121212.如果我输入19121212-1212那么它不是有效数字.并且ng-invalid ng-invalid-number类被添加到我的input元素中
当我编写我的指令时,我遵循文档如何修改内置验证器https://docs.angularjs.org/guide/forms
但它似乎不适用于type=number验证,或者我是否错过了什么?我使用角度1.3(和1.4).
我的指令代码:
angular.module('example').directive('pnrvalidator', function(){
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
var validatePnr = function(inputString){
/*
* My validation logic here. Removed for this example
*/
};
ctrl.$validators.number = function(modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
// consider empty models to be valid
return true;
}
if (validatePnr(viewValue)) {
// it …Run Code Online (Sandbox Code Playgroud) iphone ×3
angularjs ×1
cocoa-touch ×1
decimal ×1
forms ×1
ios ×1
keyboard ×1
numeric ×1
numpad ×1
uikit ×1
uitextfield ×1
validation ×1