更新:ios4.1现在已经将这个做到SDK了。你可以设置键盘类型为UIKeyboardTypeDecimalPad!完成!
在开发iphone程序的时候你可以选择各种键盘。其中的数字面板却没有带小数点。在底部的左下角有一个空白按钮,什么作用都没有。所以我将向你展示怎么将一个小数点按钮放在那里,看起来像这样的:
有一些其他的教程向你展示如何做到这样,但是我相信我的更好。因为代码简单易用,更灵活,并且UI颜色和按钮状态完美的融入键盘余下的部分(和一些教程不同)。你用来实现的代码和类似这样的:
@interface DecimalPointNumberPadViewController :UIViewController <UITextFieldDelegate> {
NumberKeypadDecimalPoint*numberKeyPad;
}
@end
@implementation DecimalPointNumberPadViewController
- (void) textFieldDidBeginEditing:(UITextField*)textField {
numberKeyPad= [[NumberKeypadDecimalPoint keypadForTextField:textField] retain];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[numberKeyPadrelease];
}
@end
·它适合于任何view conreoller上显示的任何UITextFields.
·每一个text field只会添加一个小数点.
这里是我实现的基本步骤:
1.创建一个自定义的背景透明并且文本为灰色的UIButton.
2.高亮状态我改变按钮的背景图片和文本颜色换成白色
3.我找到程序里windows的UIKeyboard并将自定义按钮添加指定位置
4.我添加一个delegate到按钮上来监听点击事件并发送事件到添加小数点到UITextField的handler
2010年6月5日更新:OS4兼容并只使用公开API
由于使用私有API违反了SDK的协议,我已经更新代码移除任何和私有API相关的代码。并且现在在OS4.0上兼容。
2010年7月20日更新:这份代码作为我开发的app的一部分并且已经被apple接受。
我的xcode的一份拷贝:
DecimalPointNumberPad-v4
谢谢
分享到:
相关推荐
Publisher: Wrox | Nov 2009 | ISBN: 0470549661 | PDF...Completely compliant with the new iPhone OS 3.0, as well as latest enhancements to Safari on iPhone, this indispensable book is a must-have resource.
苹果已经发布 iPhone OS 3.0 ,iPhone 和 iPod touch 用户可通过 iTunes 升级。iPhone OS 3.0 包含许多全新的功能,也有很多细节的改进。下面是其中 40 个最佳功能的细节描述及使用方法。 1、转发或删除短信 这个...
mQuickDo 1.1 (OS3.0) 破解版-(原iHome正式版)mQuickDo是一个iPhone,iPod Touch上很方便实用的快捷工具,让你可以通过多种手势方便快捷的来让iPhone执行各种操作。在ipod touch 3.1.3中安装后,可能会出现问题,
苹果_iPhone_4.0_使用教程.苹果_iPhone_4.0_使用教程.苹果_iPhone_4.0_使用教程.苹果_iPhone_4.0_使用教程.苹果_iPhone_4.0_使用教程.
Cocoa Touch for iPhone OS 3.0 Developer Reference,英文版本,PDF 格式,大小 18 Mb,作者 Jiva DeVoe,2009 年出版。 Join the gold rush to developing cool iPhone apps with this complete iPhone OS 3 ...
微信4.0IPHONE版
iphoneos-arm iPhone 必备工具
iphone自定义数字键盘
Wrox.Safari.WebKit.Development.for.iPhone.OS.3.0.Nov.2009.rar
iPhoneOS14.5
蓝牙4.0 iphone4s demo,可用于cc2540的板子。
the hole name:Building iPhone OS Accessories: Use the iPhone Accessories API to Control and Monitor Devices This book provides a serious, in-depth look at Apple’s External Accessory Framework and ...
iPhone 3.0: The Missing Manual (epub 格式) by David Pogue O'Reilly iPad 可用 iPhone Stanza 可用 Android aldiko 可用 By way of a printed guide to the iPhone, Apple provides only a fold-out leaflet....
蓝牙 4.0 是 2012 年最新蓝牙版本,是 3.0 的升级版本,较 3.0 版本更省电、 成本低、3 毫秒低延迟、超长有效连接距离、AES-128 加密等。蓝牙 4.0 是一款 低功耗产品,目前,iphone 4s,ipad4 等等都配备支持了 4.0...
iPhoneOS13.6.sdk 替换位置:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
Building iPhone OS Accessories Devices,英文版本,大小 5 Mb,作者 Ken Maskrey。 内容简介: Use the iPhone Accessories API to Control and Monitor Devices. 内容预览: Contents at a Glance Contents About...
as3.0 滑动技巧 模仿iphone滑动,有缓冲效果。横竖版效果都有
抱歉。。safari换行在windcode下不太好使。。格式大家见谅。。 今天给大家带来OS4.0的详细真机评测。
iphone象棋圣经4.0
Completely revised and expanded to cover the iPhone 3.0 SDK, The iPhone Developer’s Cookbook is the essential resource for developers building apps for the iPhone and iPod touch. Taking you further ...