iOS UI02_UITextField

//

//  AppDelegate.m

//  UI02_

//

//  Created by dllo on 15/7/30.

//  Copyright (c) 2015 zhozhicheng. All rights reserved.

//


#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate

-(void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    

    //输入框

    UITextField *textField=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 30)];

    textField.backgroundColor=[UIColor yellowColor];

    [self.window addSubview:textField];

    [textField release];

    

    textField.layer.borderWidth=1;

    textField.layer.cornerRadius=10;

    textField.text=@"哈哈";

    textField.textColor=[UIColor blueColor];

    //占位文本

    textField.placeholder =@"请输入用户名";

    

    textField.textAlignment=NSTextAlignmentCenter;

    textField.font=[UIFont systemFontOfSize:20];

    //secureTextEntry输入密码时候会把文本变成圆点

//    textField.secureTextEntry=YES;

    

    //设置键盘类型

//    textField.keyboardType=UIKeyboardTypeNumberPad;

    //改变return的样式

    textField.returnKeyType=UIReturnKeySearch;

    

    textField.clearsOnBeginEditing=YES;

    //清除按钮

    textField.clearButtonMode=UITextFieldViewModeAlways;

    //创建一个view

    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(200, 100, 100, 50)];

    view.backgroundColor=[UIColor blueColor];

    //弹出一个自定义视图,默认是键盘

//    textField.inputView=view;

    //给键盘添加一个辅助视图

    textField.inputAccessoryView=view;

    

    //textfield设置代理人

    textField.delegate = self;

    

    //点击return按钮  回收键盘


    return YES;

}

//实现协议方法

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    NSLog(@"测试return按钮");

    //这句话是实现回收键盘的关键

    [textField resignFirstResponder];

    return YES;

}


-(BOOL)textFieldShouldClear:(UITextField *)textField

{

    NSLog(@"测试清除按钮");

    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:.

}


@end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章