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


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