zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    MySQL
    Date和String转换
    Spring-test事务自动回滚
    java多线程:生产者和消费者模式(wait-notify) : 单生产和单消费
    制作ISO文件 与 提取ISO文件
    windows10 更换密码
    win 添加网络位置共享 && win 实用快捷键
    ubuntu16 安装mysql5.7
    ubuntu16 中chkconfig 命令不能使用
    mysql 5.7 初始化密码或随机密码
  • 原文地址:https://www.cnblogs.com/wohaoxue/p/4764797.html
Copyright © 2011-2022 走看看