iOS中的文字框(UITextField)

來源:互聯網
上載者:User

標籤:

#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

 

iOS中的文字框(UITextField)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.