码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UI02_UITextField

时间:2015-07-31 09:06:00      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

//

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


版权声明:本文为博主原创文章,未经博主允许不得转载。

iOS UI02_UITextField

标签:

原文地址:http://blog.csdn.net/cheng_xiansheng/article/details/47164695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!