UI 03 UITextField

UITextField 继承于 UIControl .

特殊的技能是可以输入.

// 输入框
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 50, 200, 40)];
    textField.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:textField];
    [textField release];

    textField.layer.borderWidth = 1;
    textField.layer.cornerRadius = 10;

    // 初始文本
    //textField.text = @"贱男";
    textField.textColor = [UIColor purpleColor];

    // 占位文本
    textField.placeholder = @"请输入姓名";

    textField.textAlignment = NSTextAlignmentCenter;
    textField.keyboardType = UIKeyboardTypeDefault;

    // return 按钮切换样式
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearsOnBeginEditing = YES;
    //textField.secureTextEntry = YES;

    // 清除按钮的样式
    textField.clearButtonMode =  UITextFieldViewModeAlways;

    // 创建一个view
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 20, 20)];
    view.backgroundColor = [UIColor orangeColor];

    // 弹出一个自定义的视图,默认是键盘
   textField.inputView = view;

    // 给键盘添加一个辅助视图.
    textField.inputAccessoryView = view;

    // 给textfield设置代理人.
    textField.delegate = self;

    // 点击Return 按钮,回收键盘.(协议)

下面的方法是:

// 实现协议方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"测试return按钮");
    NSLog(@"%@",textField.text);

    // 这句话是回收return键盘
    [textField resignFirstResponder];
    return YES;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField{
    NSLog(@"测试清除按钮");
    return YES;
}

// UITextField 继承于UIControl 所以也有这个点击方法.
- (void)click:(UITextField *)textField{
}

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

时间: 2024-07-30 14:41:04

UI 03 UITextField的相关文章

UI 03 UIButton 和 UITextField

可以将UIButton 与 UITextField 结合起来使用, 产生如下图的效果. // 新建一个Button UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(100, 300, 50, 50); button.backgroundColor = [UIColor cyanColor]; [self.window addSubview:button]; but

UI 03 关于UITextField键盘遮挡问题

首先,需要引头文件, 签订协议 已改成 MRC ! //1.三个textfield UITextField *textField1 = [[UITextField alloc]initWithFrame:CGRectMake(100, 200, 150, 40)]; textField1.layer.borderWidth = 1; textField1.layer.cornerRadius = 10; [self.view addSubview:textField1]; textField1.

ios开发UI篇—UITextfield

概述 UITextField在界面中显示可编辑文本区域的对象. 您可以使用文本字段来使用屏幕键盘从用户收集基于文本的输入.键盘可以配置许多不同类型的输入,如纯文本,电子邮件,数字等等.文本字段使用目标操作机制和委托对象来报告在编辑过程中所做的更改. 除了基本的文本编辑行为之外,还可以将叠加视图添加到文本字段以显示其他信息并提供其他可定位控件.您可以为诸如书签按钮或搜索图标等元素添加自定义叠加视图.文本字段提供内置的叠加视图来清除当前文本.自定义覆盖视图的使用是可选的. 属性和方法 初始化 UIT

UI 03 LTView

LTView 是自写的继承于 UIView 的类 这其中创建一个UILabel 和一个 UITextField ; 这样可以少些一半的代码. 代码如下: LTView.h #import <UIKit/UIKit.h> @interface LTView : UIView<UITextFieldDelegate> // 因为要在类的外部获取输入框的内容,修改Label的标题,所以我们把这两部分作为属性写在.h这样在外部可以直接进行修改和设置 @property(nonatomic,

iOS开发-UI (五)UITextField

UITextField使用 1.创建方式 例: UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; 2.常用方法和属性 1)边框样式 @property(nonatomic)  UITextBorderStyle   borderStyle; UITextBorderStyleNone                       没有边框,背景默认为透明 UITextBorderS

iOS开篇——UI之UITextField

创建文本输入框 UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 250, 40)]; 设置边框样式 textField.borderStyle = UITextBorderStyleRoundedRect; /* typedef NS_ENUM(NSInteger, UITextBorderStyle) { UITextBorderStyleNone, 无效果 UITextBorderS

UI基础:UITextField

UITextField 继承自UIControl,他是在UILabel基础上,对了文本的编辑.可以允许用户输入和编辑文本 UITextField的使用步骤 1.创建控件 UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 300, 50)]; textField.tag=100;//为textField赋tag,目的是可以通过父视图找到textField 2.设置属性 (1).设置背景 text

iOS学习UI之UITextfield

UITextField->UIControl->UIView 常用属性 1.图片对象转化为颜色对象 textField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"DOVE 1"]]; 2.borderStyle 边框样式 textField.borderStyle = UITextBorderStyleNone; 3.contentVerticalAlignment 文本垂直

UI基础-UITextField &#160; &#160;UIButton &#160; delegate

UITextField UITextField(输入框):是控制文本输入和显示的控件,在App中UITextField出现频率也比较高. Ios系统借助虚拟键盘实现输入,当点击输入框,系统会自动调出键盘,方便你进一步操作.在你不需要输入的时候,可以使用回收键盘的方法,收回弹出的键盘. UITextField和UILabel相比,UILabel主要用于文字显示,不能编辑,UITextField允许用户编辑文字(输入) 文本显示 外观控制 UIButton UIButton(按钮):是响应用户点击的