zoukankan      html  css  js  c++  java
  • UI控件(UITextField)

    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UITextField* textField1 = [[UITextField alloc] init];
        
        //设置代理表示实现协议 UITextFieldDelegate
        textField1.delegate = self;
        textField1.frame = CGRectMake( 20, 120, 280, 30 );
        //    边框样式
        //    typedef enum {
        //        UITextBorderStyleNone,            无边框
        //        UITextBorderStyleLine,            直线边框
        //        UITextBorderStyleBezel,           左边框、上边框加粗
        //        UITextBorderStyleRoundedRect      圆角
        //    } UITextBorderStyle;
        textField1.borderStyle = UITextBorderStyleRoundedRect;
        textField1.text = @"hello,textfield";
        textField1.placeholder = @"please input the text";
        
        //设置字体及大小
        textField1.font = [UIFont fontWithName:@"Arial" size:10.0f];
        //设置字体颜色
        textField1.textColor = [UIColor blueColor];
        //    typedef enum {
        //        UITextFieldViewModeNever,             重不出现
        //        UITextFieldViewModeWhileEditing,      编辑时出现
        //        UITextFieldViewModeUnlessEditing,     除了编辑外都出现
        //        UITextFieldViewModeAlways             一直出现
        //    } UITextFieldViewMode;
        textField1.clearButtonMode = UITextFieldViewModeAlways;
        
        //采用星号加密显示
        textField1.secureTextEntry = NO;
        
        //定义弹出的软键盘类型
        //UIKeyboardTypeDefault     默认全部
        //UIKeyboardTypeNumberPad   数字键盘
        //类型较多,此处省略
        textField1.keyboardType = UIKeyboardTypeDefault;
        
        //定义软键盘上的回车按键的样式
        //    UIReturnKeyDefault,   默认 灰色按钮,标有Return
        //    UIReturnKeyGo,        标有Go的蓝色按钮
        //    类型较多此处省略
        textField1.returnKeyType = UIReturnKeyDefault;
        
        //左侧或右侧增加图片
        UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"person.png"]];
        textField1.leftView=image;
        textField1.leftViewMode = UITextFieldViewModeAlways;
        
        
        [self.view addSubview:textField1];
    }
    
    #pragma mark - TextField Delegates
    
    //开始编辑时出发回调
    -(void)textFieldDidBeginEditing:(UITextField *)textField{
        NSLog(@"%s", __FUNCTION__);
    }
    
    //结束编辑时出发回调(软键盘消失)
    -(void)textFieldDidEndEditing:(UITextField *)textField{
        NSLog(@"%s", __FUNCTION__);
    }
    
    //回车时被回调
    -(BOOL) textFieldShouldReturn:(UITextField *)textField{
        NSLog(@"%s", __FUNCTION__);
        [textField resignFirstResponder];//若该行注释则软件盘在回车后部消失
        return YES;
    }
    
    @end
  • 相关阅读:
    .NET正则基础之——平衡组
    正则基础之——贪婪与非贪婪模式
    正则应用之——日期正则表达式
    文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换(完整版,收集,整理)
    linux c 发送邮件
    select, poll和epoll的区别(转)
    linux c 中文支持
    修改远程桌面连接端口(PortNumber)
    libhdfs编译,安装,配置,使用
    C语言字节对齐详解
  • 原文地址:https://www.cnblogs.com/Fredric-2013/p/5185655.html
Copyright © 2011-2022 走看看