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

 

转载于:https://www.cnblogs.com/wohaoxue/p/4764797.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值