UItextField
一、创建一个UITextField时候默认就弹出键盘
    1 对齐方式
    textField.textAlignment = NSTextAlignmentCenter;
    2 是否允许输入
    textField.enabled = YES;
    3 是否清空输入框
    textField.clearsOnBeginEditing = YES;
    4 是否密文  NO 的时候是明文  原点的颜色跟字体的颜色一致
    textField.secureTextEntry = YES;
    5 键盘的弹出格式
    textField.keyboardType = UIKeyboardTypeNumberPad;
    6 回车return键的设置
    textField.returnKeyType = UIReturnKeyNext;
    7 自定义输入键盘视图
    textField.inputView = inputView;  // 只有最后一个参数有用,最后一个参数用来控制高度
    8 设置自定义键盘的那一条横幅
    textField.inputAccessoryView = inputAccessView;
    9 边框样式    圆角
    textField.borderStyle = UITextBorderStyleRoundedRect;
    10 清除按钮
    textField.clearButtonMode = UITextFieldViewModeWhileEditing; // 当开始编辑的时候就显示清除按钮
    11 左视图、右视图
    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    leftView.backgroundColor = [UIColor greenColor];
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeWhileEditing;
    textField.rightView = leftView;
    textField.rightViewMode = UITextFieldViewModeWhileEditing;
二、  使用协议中的方法的步骤
     1.遵循协议
     2.实现方法
     3.设置代理
// 遵循协议
               @interface AppDelegate : UIResponder <UIApplicationDelegate,UITextFieldDelegate>  
// 设置代理
        field.delegate = self;
//实现方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
     {
取消第一响应者 回收键盘
  [textField resignFirstResponder];
     *  1.判断第一个是不是第一相应者
        2.如果是就让第二个变成第一响应者
        3.如果点的是第二个就让第三个变成第一响应者
        4.如果是第三个就回收键盘
   if (textField.tag == 100 && [textField isFirstResponder] == YES) {
        NSLog(@"点的是第一个,将第二个成为第一响应者。");
        UITextField *f1 = (UITextField *)[self.window viewWithTag:101];
        [f1 becomeFirstResponder];
    } else if (textField.tag == 101 && [textField isFirstResponder] == YES) {
        NSLog(@"点的是第二个,将第三个成为第一响应者。");
        UITextField *f1 = (UITextField *)[self.window viewWithTag:102];
        [f1 becomeFirstResponder];
    } else if (textField.tag == 102 && [textField isFirstResponder] == YES) {
        NSLog(@"点的是第三个,回收键盘");
        [textField resignFirstResponder];
    }
    return YES;
}
   /**
     *  第一响应者
        如果取消第一响应者  键盘回收
     */
    /**
     - (UIResponder*)nextResponder;
     - (BOOL)canBecomeFirstResponder;    // default is NO
     - (BOOL)becomeFirstResponder;
     - (BOOL)canResignFirstResponder;    // default is YES
     - (BOOL)resignFirstResponder;
     - (BOOL)isFirstResponder;
     */
UIButton
     *  创建一个Button, 一般不适用init方法  使用类方法
        注意:不用管理内存
1   UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // UIButtonTypeCustom  自定义类型的
    button.frame = CGRectMake(100, 100, 100, 100);
    button.backgroundColor = [UIColor greenColor];
2设置点击的方法
    [button addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
   
3三种状态  普通  高亮  选中
    [button setTitle:@"高亮" forState:(UIControlStateHighlighted)];
    [button setTitle:@"普通" forState:(UIControlStateNormal)];
    [button setTitle:@"选中" forState:(UIControlStateSelected)];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
4 设置按钮  背景图片    // 一般都使用背景图片
5 创建一张图片
    UIImage *image = [UIImage imageNamed:@"Normal"];// 如果不是png 格式就要写全称
    [button setBackgroundImage:image forState:(UIControlStateNormal)];
    UIImage *image1 = [UIImage imageNamed:@"Selected"];
    [button setBackgroundImage:image1 forState:(UIControlStateSelected)];
    UIImage *image2 = [UIImage imageNamed:@"HightLighted"];
    [button setBackgroundImage:image2 forState:(UIControlStateHighlighted)];
   
6设置前景图片
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:image1 forState:UIControlStateSelected];
    [button setImage:image2 forState:UIControlStateHighlighted];
7取出各种状态下的标题
    NSLog(@"%@", [button titleForState:(UIControlStateNormal)]);
8取出各种状态下的图片
    UIImage *image3 = [button imageForState:(UIControlStateNormal)];
9 button.backgroundColor = [UIColor yellowColor];
    设置button的选中状态    高亮状态中有普通状态才能切换过去
    选中未选中之间切换
    if ([button isSelected]) {
        button.selected = NO;
    } else {
        button.selected = YES;
    }
10 与上面的代码是一样的。
    button.selected = !button.selected;
11 . iOS 后台运行 (小退出和大退出的方法分别调用了那个方法)
- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"1%s%d", __FUNCTION__,__LINE__);
    NSLog(@"程序小退出状态。");
    // 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.
// 当应用程序即将从活跃到不活跃的状态。这可能发生某些类型的暂时中断(如传入的电话或短信)或当用户退出应用程序,它开始过渡到后台状态。
// 使用这种方法暂停正在进行的任务,禁用计时器,和节流OpenGL ES帧率。游戏应该使用这种方法暂停游戏。
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"2%s%d", __FUNCTION__,__LINE__);
    NSLog(@"程序进入后台挂起状态");
    // 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.
  // 使用这种方法释放共享资源,保存用户数据,对计时器无效,存储足够多的应用程序状态信息来恢复您的应用程序的当前状态,以防它终止。
  // 如果您的应用程序支持后台执行,当用户退出时调用此方法代替applicationWillTerminate:。
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"3%s%d", __FUNCTION__,__LINE__);
    NSLog(@"进入前台。");

    // 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 {
    NSLog(@"4%s%d", __FUNCTION__,__LINE__);
    NSLog(@"进入激活状态");

    // 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 {
    NSLog(@"5%s%d", __FUNCTION__,__LINE__);
    NSLog(@"程序意外退出");

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// 调用应用程序时终止。如果适当的保存数据。看到也applicationDidEnterBackground:。
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    NSLog(@"内存发出警告");

}
--------------------------------------------------------------------------
一、键盘风格 UIKit框架支持8种风格键盘。
typedef enum {
UIKeyboardTypeDefault, // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation, //标准电话键盘,支持+*#等符号

UIKeyboardTypeURL, UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, UIKeyboardTypeNamePhonePad, UIKeyboardTypeEmailAddress,

} UIKeyboardType;

用法用例:

// URL键盘,有.com按钮;只⽀支持URL字符 //数字键盘

// 电话键盘
// 电话键盘,也⽀支持输⼊人名字
// 用于输入电子邮件地址的键盘

textView.keyboardtype = UIKeyboardTypeNumberPad;

二、键盘外观

typedef enum { UIKeyboardAppearanceDefault, UIKeyboardAppearanceAlert,

} UIKeyboardAppearance;

用法用例:
// 默认外观:浅灰色 //深灰/石墨色

textView.keyboardAppearance=UIKeyboardAppearanceDefault;

三、回车键
typedef enum {
UIReturnKeyDefault, //默认:灰色按钮,标有Return UIReturnKeyGo, //标有Go的蓝色按钮 UIReturnKeyGoogle, //标有Google的蓝色按钮,⽤于搜索 UIReturnKeyJoin, //标有Join的蓝色按钮 UIReturnKeyNext, //标有Next的蓝色按钮 UIReturnKeyRoute, //标有Route的蓝色按钮 UIReturnKeySearch, //标有Search的蓝色按钮 UIReturnKeySend, //标有Send的蓝色按钮 UIReturnKeyYahoo, //标有Yahoo!的蓝色按钮,用于搜索 UIReturnKeyDone, //标有Done的蓝色按钮 UIReturnKeyEmergencyCall, //紧急呼叫按钮

} UIReturnKeyType;

用法用例:

textView.returnKeyType=UIReturnKeyGo;

四、自动大写
typedef enum {
UITextAutocapitalizationTypeNone, //不⾃自动大写 UITextAutocapitalizationTypeWords, //单词首字⺟大写
UITextAutocapitalizationTypeSentences, //句子首字母大写
UITextAutocapitalizationTypeAllCharacters, //所有字母大写 } UITextAutocapitalizationType;
用法用例:

textField.autocapitalizationType = UITextAutocapitalizationTypeWords;

五、自动更正
typedef enum { UITextAutocorrectionTypeDefault,//默认 UITextAutocorrectionTypeNo,//不自动更正 UITextAutocorrectionTypeYes,//自动更正

} UITextAutocorrectionType;

用法用例:

textField.autocorrectionType = UITextAutocorrectionTypeYes;

六、安全⽂文本输入
textView.secureTextEntry=YES;
开启安全输⼊入主要是用于密码或⼀一些私⼈人数据的输⼊入,此时会禁用自动更正和自此缓存。

UI一揽子计划 2 (UITextField  UIButton)相关推荐

  1. UI一揽子计划 8 (UINavigationController 、界面通信 、NSTimer  、NSUserDefaults)

    一.UINavigationController       //  创建一个导航控制器     // 创建一个控制器作为根控制器 去管理     RootViewController *rootVC ...

  2. UI一揽子计划 24 (MVC、通知、)

    一.MVC  Model - View - Controller 即  模型 - 视图 - 控制器 Modle (模型) 存储 处理数据 为应用程序提供数据. View (视图)展示用户界面视图,提供 ...

  3. UI一揽子计划 3 (自定义视图、UIViewControllor、屏幕旋转判断和重布局)

    一.UIView自定义视图      因为在实际开发过程中,可能由于繁琐的创建相同的Label.textfield和Button组合,为了实现编程工作的高效率,我们可以自定义视图,并且将它们封装起来. ...

  4. UI一揽子计划 20 (豆瓣实战之图片缓存 、豆瓣实战之详情界面(自适应行高) 、豆瓣实战之登陆注销、刘新林分享之UIAlertController)

    一.图片缓存 ActivityModel.m 如果数据加载完毕就将图片放到缓存中. #pragma mark -- imageDownLoader 代理方法 //  成功返回data - (void) ...

  5. UI一揽子计划 1 (UIView UILabel)

    第一天 1.UIView ·建立一个空模板后,首先将ARC模式关闭,因为iOS采用MRC模式,即手动管理内存. ·重写dealloc方法. - (void)dealloc { [_window rel ...

  6. UI一揽子计划 7 ( UIScrollView、 UIPageControl、综合所学简单相册)

    ---- 创建一个UIScrollView     UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen ma ...

  7. UI一揽子计划 4 (Touch 、摇一摇、响应者链)

    一.touch - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event //开始触摸,就只被执行一次 {  //  NSLog(@ ...

  8. UI一揽子计划 6 (UIControl、UISegmentedControl、UIImageView插入数组图片、UISlider)

    一 UIControl 是所有控制类控件的基类. ·  比如UIButton    UISlider     UISegmentedControl   等只要跟控件有关系的都继承于UIControl类 ...

  9. UI一揽子计划 23 (动画的使用场景、UIView动画、CGAffineTransform2D仿射变换、CALayer、CAAnimation、)

    在iOS 中的动画是指一些视图上的过渡效果,合理利用动画能提高用户体验. 一. UIView动画 1). UIView动画块的使用 ([UIView beginAnimations: nil cont ...

最新文章

  1. Mysql insert语句的优化
  2. android camera viewport rect,Unity 实现屏幕抖动效果(通过Camera Viewport Rect)
  3. 【数据结构】哈夫曼树与哈夫曼编码
  4. “ORA-01034 - Oracle not available”和“ORA-27101 - shared memory realm does not exist”
  5. CUDA学习(三十六)
  6. 内核网络输出帧的处理
  7. 文艺小清新手绘秋季秋天叶片,值得设计师收藏的好素材
  8. 安卓中的数据存储方式以及ContentProvider的简单介绍
  9. 卸载Windows的引导界面中的变色龙选项
  10. r语言如何计算t分布临界值_R语言系列第四期:R语言单样本双样本差异性检验...
  11. 史上最“奇葩”相亲男惊呆网友:你那么普通,却那么自信
  12. 死理性派恋爱法:拒绝掉前面37%的人
  13. ubuntu安装视频播放器
  14. C语言中什么叫做左值?右值?
  15. 学生成绩管理系统(转载)
  16. AdaptiveAvgPool1D内部实现
  17. RISC-V应用于高性能处理器的可能性
  18. ByteBuffer使用揭秘
  19. 博时金牛杯(三强)公开大赛
  20. 奶瓶仔xp主题【主题世界】

热门文章

  1. 运营小技能:分析订阅号文章数据来提升账号权重
  2. decorator 装饰器
  3. lammps教程:变量前缀v_/c_/f_的用法
  4. mysql oltp olap_数据库 OLAP、OLTP的介绍和比较
  5. C#之读取数据:DataReader对象
  6. 胡博君解Java中简单工厂模式
  7. idea创建module项目
  8. 教你如何将电脑瞬间关掉
  9. 嵌入式计算机系统设计第四次实验报告
  10. CT和MRI的局限性和克服措施