iOS UI02_UITextField

来源:互联网 发布:java形参实参 编辑:程序博客网 时间:2024/05/17 22:47

//

//  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];

    [superdealloc];

}


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

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    [_window release];

    

    //输入框

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

    textField.backgroundColor=[UIColoryellowColor];

    [self.windowaddSubview:textField];

    [textFieldrelease];

    

    textField.layer.borderWidth=1;

    textField.layer.cornerRadius=10;

    textField.text=@"哈哈";

    textField.textColor=[UIColorblueColor];

    //占位文本

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

    

    textField.textAlignment=NSTextAlignmentCenter;

    textField.font=[UIFontsystemFontOfSize:20];

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

//    textField.secureTextEntry=YES;

    

    //设置键盘类型

//    textField.keyboardType=UIKeyboardTypeNumberPad;

    //改变return的样式

    textField.returnKeyType=UIReturnKeySearch;

    

    textField.clearsOnBeginEditing=YES;

    //清除按钮

    textField.clearButtonMode=UITextFieldViewModeAlways;

    //创建一个view

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

    view.backgroundColor=[UIColorblueColor];

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

//    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


0 0
原创粉丝点击