码迷,mamicode.com
首页 > 其他好文 > 详细

UITextField(详细设置)

时间:2015-06-13 21:33:54      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 

 

技术分享

 

 

 

 

技术分享

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

  

UITextField(详细设置)

标签:

原文地址:http://www.cnblogs.com/deng37s/p/4574027.html

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