• UITextField(详细设置)


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        lb=[[UILabel alloc] initWithFrame:CGRectMake(60, 150, 200, 50)];
        lb.text=@"label";
        ///字体颜色
        lb.textColor =[UIColor blueColor];
        ///背景颜色
        lb.backgroundColor=[UIColor grayColor];
        ///对齐方式
        lb.textAlignment=NSTextAlignmentCenter;
        
        [self.view addSubview:lb];
        
    //    UIImage *image = [UIImage imageNamed:@"001.png"];
    //    [self.view addSubview:image];
        
        
      textfield = [[UITextField alloc] initWithFrame:CGRectMake(10, 20, 300, 70)];
        ///背景颜色
        //[textfield setBackgroundColor:[UIColor redColor]];
        textfield.backgroundColor=[UIColor grayColor];
       ///对齐方式
        textfield.textAlignment=NSTextAlignmentCenter;
        ///边框样式
        textfield.borderStyle=UITextBorderStyleBezel;
        ///占位符
        textfield.placeholder=@"请输入账号";
        ///密码输入
        textfield.secureTextEntry=YES;
        ///垂直模式
        textfield.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        ///清除按钮
        textfield.clearButtonMode=UITextFieldViewModeAlways;
        ///返回键类型
        textfield.returnKeyType=UIReturnKeyDone;
        ///键盘类型
        textfield.keyboardType=UIKeyboardTypeAlphabet;
        ///设置代理
        textfield.delegate=self;
        
        
        [self.view addSubview:textfield];
        
    
        
        
    	// Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    ///每一次改变输入框的内容都会掉用
    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
        NSLog(@"range:%@,string "%@"",NSStringFromRange(range),string);
        ///禁止输入的内容
        if ([string isEqualToString:@"h"]) {
            return NO;
        }
        return YES;
        
        
    }
    
    ///触发点击事件
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        [textfield resignFirstResponder];
        
         lb.text=textfield.text;
    }
    
    ///return触发
    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
        [textfield resignFirstResponder];
        
        lb.text=textfield.text;
        
        return YES;
    }
    
    ///允许/禁止清除按钮
    - (BOOL)textFieldShouldClear:(UITextField *)textField{
        return YES;
    }
    
    
    
    
    @end
    

      

  • 相关阅读:
    周末复习所接触到的知识点
    新增一些需要记住的知识点和坑
    讨厌烦人的编码问题''
    dictionary 字典相关操作
    一些列表的基础知识和操作
    简单字符串语句
    一些简单的str语句
    c#学习之前言
    第六课时之HTML标题
    第五课时之HTML属性
  • 原文地址:https://www.cnblogs.com/deng37s/p/4574027.html
Copyright © 2020-2023  润新知