iOS中的文本框(UITextField)

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    UIView *containterView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    containterView.tag = 100;
    containterView.backgroundColor = [UIColor whiteColor];

    [self.window addSubview:containterView];

    [containterView release];

    /*
     UITextField:是在UILabel的基础上,多了文字编辑的共更能,可以允许用户输入以及编辑文字.继承自UIControl
     UITextField的使用步骤
     1.创建
     2.编辑属性
     3.添加到父视图
     4.释放所占空间
     */

    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
     textField.tag = 200;
    [containterView addSubview:textField];

    textField.backgroundColor = [UIColor whiteColor];

    [textField release];

    //设置输入框的提示文字(占位符)
    textField.placeholder = @"请输入密码";
    //textField.text = @"38尺";

    textField.font = [UIFont fontWithName:@"AvenirNextCondensed-HeavyItalic" size:35];

    //文字对应方式
    //textField.textAlignment = NSTextAlignmentCenter;
    textField.textAlignment = NSTextAlignmentLeft;
    //设置文本框是否能被编辑
    //textField.enabled = NO;
    //当输入框开始编辑时,清空输入框中的内容
    //textField.clearsOnBeginEditing = YES;
    //textField.clearsOnInsertion = YES;
    //textField.clearsContextBeforeDrawing = YES;
    //textField.textColor = [UIColor blueColor];
    textField.font = [UIFont systemFontOfSize:28];
    //设置输入框以密码形式显示
    textField.secureTextEntry = YES;
    //数字键盘
    //textField.keyboardType = UIKeyboardTypeNumberPad;
    //设置return键的类型样式
    textField.returnKeyType = UIReturnKeyGo;
    //设置输入边框样式
    textField.borderStyle = UITextBorderStyleRoundedRect;

    //自定义键盘
    /*
    UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

    inputView.backgroundColor = [UIColor cyanColor];

     textField.inputView = inputView;
     [inputView release];
    */
    /**
     *  设置键盘上得辅助视图
     */
//    UIView *inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
//    inputAccessoryView.backgroundColor = [UIColor yellowColor];
//    textField.inputAccessoryView = inputAccessoryView;
//    [inputAccessoryView release];
    //设置输入框 清除按钮模式
    //textField.clearButtonMode =  UITextFieldViewModeWhileEditing;

    //设置输入框代理

    textField.delegate = self;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (void)dealloc
{
    [_window release];
    [super dealloc];
}
#pragma mark -- UITextFieldDelegate
//当点击减盘上得return触发该方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
{
    //取消第一响应这
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UIView *containerView = [self.window viewWithTag:100];
    UITextField *textFD = (UITextField *)[containerView viewWithTag:200];
    [textFD resignFirstResponder];
}
@end
时间: 2024-12-20 22:34:27

iOS中的文本框(UITextField)的相关文章

iOS中UISearchBar(搜索框)使用总结

iOS中UISearchBar(搜索框)使用总结 初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar     UISearchBar * bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)];     [self.view addSubview:bar]; @property(nonatomic)        UIBarStyle              ba

如何让IOS中的文本实现3D效果

本转载至 http://bbs.aliyun.com/read/181991.html?spm=5176.7114037.1996646101.25.p0So7c&pos=9     zhedianshi 级别: 帮帮团 发帖 487 云币 430 加关注 写私信 只看楼主 更多操作楼主  发表于: 2014-06-10 我想要在IOS中对一些文本进行3D效果渲染,使用了UIKit和标准视图控制器. 实现之的效果大概能成为这样:   能不能通过iOS和UIKit实现?我只用了一个静态PNG图片,

20140527-在jQuery中设置文本框回车事件

20140527-在jQuery中设置文本框回车事件 该代码要完成的效果是,用户在文本框输入完毕以后,按下回车键,立即触发"搜索"的单击事件. 例如: $("#search_user_name").keydown(function (e) {         // search_user_name为文本框ID         var curKey = e.which;         if (curKey == 13) {             // search

Asp.net中使用文本框的值动态生成控件的方法

这篇文章主要介绍了Asp.net中使用文本框的值动态生成控件的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下 看到一个网友,有论坛上问及,动态的生成checkbox控件,在文本框中输入一个"花"字,点一下"生成"按钮,就会在下面生成一个checkbox,它的text属性是"花".再输入一个"鸟",点一下按钮,就会生成第二个checkbox控件,text属性是"鸟"... Insus.NET的解决方法

Rdlc技巧,rdlc报表中获取文本框或某个表格单元格中的内容

在RDLC报表中,随意摆放的控件,排列看起来很整齐,但是生成WEB后看就不是很友好了,导出PDF可能又是一个样, 解决这个办法就是把这些摆放在一个容器内,比如Table 内 用ReportItems这个属性来取value值.细节如下 =ReportItems!textbox1.Value + ReportItems!textbox12.Value 注意,页头页脚可以取Body里的值,但是Body里不可以取页头与页脚的值 Rdlc技巧,rdlc报表中获取文本框或某个表格单元格中的内容

word中创建文本框

word中创建文本框         在插入中点击"文本框"选项卡,如下图所示:        手工添加自己想要的文本框格式,然后选择所创建的文本框,在工具栏处会发现多了一个"格式"选项卡,点击,可以对文本框进行设置,如外观的纹理等等,如下图所示: word中创建文本框

IOS不触发文本框输入中文的keyup事件

问题描述:IOS不触发文本框输入中文的keyup事件,在输入中文之后需要点击回退按键,才会开始搜索.问题分析:IOS的输入法(不管是第三方还是自带)能检测到英文或者数字的keyup事件,检测不到中文的keyup事件.解决方案:把keyup事件换成[input]和[propertychange]事件. var eventName = (navigator.userAgent.indexOf("MSIE")!=-1) ? "propertychange" :"

cell中的文本框————bug

根据要求需要制作一个报表,我一UItableView为主体,自定义cell,在cell中添加文本框以便输入相应字段, 要求:1,当我们改变表格对应行的内容时会自动计算相应列的总和[相信大家用过Excel 原理差不多了] 我再文本框失去焦点时,调用代理方法通知UItableView的页面进行计算并刷新数据源和表格 bug:导致文本框不能正常的获取焦点,但我们页面上已经有获取焦点的文本框时,又去点击另外的文本框,此时新的文本框不能获取焦点,但会弹出键盘,且键盘无法收起,通过监听文本框的代理发项,文本

实现:C#窗体中的文本框只能输入中文汉字,其他输入无效。问:正则表达式怎么用?

原文:实现:C#窗体中的文本框只能输入中文汉字,其他输入无效.问:正则表达式怎么用? private void textBox1_KeyPress(object sender, KeyPressEventArgs e) ? ? ? ? { ? ? ? ? ? ? Regex rg = new Regex("^[\u4e00-\u9fa5]$"); ? ? ? ? ? ? if (!rg.IsMatch(e.KeyChar.ToString()) && e.KeyChar