IOS開發之UITextField



#import "AppDelegate.h"app


@interface AppDelegate ()less


@end ide


@implementation AppDelegate字體



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

    // Override point for customization after application launch.this

     _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];spa

    [_window setBackgroundColor:[UIColor whiteColor]];.net

    

    

    //=====================================3d

    //UITextField:UIControl:UIViewrest

   //1.建立一個UITextField對象

    UITextField *textField = [[UITextField alloc ]initWithFrame:

                              CGRectMake(100, 100, 200, 50)];

    

    //2.添加到界面上

    [_window addSubview:textField];

    

    //3.設置背景色

    [textField setBackgroundColor:[UIColor yellowColor]];

    

    //=============textField和文字相關屬性================

    //1.text(能夠經過這個屬性改變textField顯示的文字

    //更多的時候是經過這個屬性去拿到裏面的textFieldtext)

    textField.text = @"hello luhan";

    

    //2.文字顏色

    textField.textColor = [UIColor redColor];

    

    //3.設置字體

    textField.font = [UIFont systemFontOfSize:17];

    

    //4.設置居中模式

    textField.textAlignment = NSTextAlignmentLeft;

    

    //5.佔位文字(淺灰文字不能夠改變);(提示文字)

    //只有textField裏面沒有文字纔會顯示佔位文字;

    //textField.text = nil;

    [textField setPlaceholder:@"請輸入名字"];

    

    //6.是否在開始編輯的時候清空文字(默認是NO;

    [textField setClearsOnBeginEditing:YES];

    

    //7.

    

    //=================textField和顯示相關的屬性==================

//    UITextBorderStyleNone,(默認是沒有邊框的)

//    UITextBorderStyleLine,

//    UITextBorderStyleBezel,

//    UITextBorderStyleRoundedRect

    //1.設置邊框風格

    [textField setBorderStyle:UITextBorderStyleRoundedRect];

    

    //2.設置清除按鈕模式

//    UITextFieldViewModeNever,默認一致都不顯示

//    UITextFieldViewModeWhileEditing,編輯的時候顯示

//    UITextFieldViewModeUnlessEditing,除了編輯的時候都要顯示

//    UITextFieldViewModeAlways一致顯示

    [textField setClearButtonMode:UITextFieldViewModeWhileEditing];

    

   //3.設置textField的左視圖(能夠傳任意繼承子UIView的視圖對象)

    //設置左視圖座標是沒有意義的.

    UILabel *leftLabel = [[UILabel alloc]initWithFrame:

                      CGRectMake(0, 0, 50, 50)];

    leftLabel.text = @"帳號:";

    leftLabel.textColor = [UIColor grayColor];

    

    textField.leftView = leftLabel;

    //4.設置左視圖模式(默認是一直不顯示)

    //    UITextFieldViewModeNever,默認一致都不顯示

    //    UITextFieldViewModeWhileEditing,編輯的時候顯示

    //    UITextFieldViewModeUnlessEditing,除了編輯的時候都要顯示

    //    UITextFieldViewModeAlways一致顯示

    [textField setLeftViewMode:UITextFieldViewModeAlways];

    

    //5.設置自定製的鍵盤;(只有設置高度是有效的)

   UIView *inputView = [[UIView alloc]initWithFrame:

     CGRectMake(0, 0,0,20)];

    

    inputView.backgroundColor = [UIColor yellowColor];

    [textField setInputAccessoryView:inputView];

    

    //6.設置二級鍵盤

    UIView *accessoryView = [[UIView alloc]initWithFrame:

                             CGRectMake(0, 0, 0, 10)];

    accessoryView.backgroundColor = [UIColor redColor];

    [textField setInputAccessoryView:accessoryView];

    

    

    

    

    //==================textField和編輯相關的屬性===========================

    //判讀當前textField是否處於編輯狀態

    //編輯狀態:

    BOOL ret = textField.isEditing;

    NSLog(@"是否處於編輯狀態:%@",ret?@"是在編輯":@"沒有編輯");

    

    

    

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

}


@end

相關文章
相關標籤/搜索