UITextField 基本设置

UITextField--基本设置 iPhone UITextField - Change placeholder text color
 

1、UILabel的基本设置

2、UITextFiel的基本设置

3、设置UITextFiel输入长度的限制

4、弹出提示消息

5、UITextFiel输入时自动隐藏键盘

- (void)LY_Display
{
UILabel *LY_Label = [[UILabel alloc] initWithFrame:CGRectMake(60, 180, 60, 30)];
[self.view addSubview:LY_Label];
LY_Label.backgroundColor = [UIColor clearColor];
LY_Label.text = @"密 码";
LY_Label.font= [UIFont fontWithName:@"zapfino" size:(15.0f)]; //字体设置


UITextField *LY_Text = [[UITextField alloc] initWithFrame:CGRectMake(143, 180, 80, 30) ];
[self.view addSubview:LY_Text];
LY_Text.backgroundColor = [UIColor whiteColor];
[LY_Text setBorderStyle:UITextBorderStyleLine]; //边框设置
LY_Text.placeholder = @"password"; //默认显示的字
LY_Text.font = [UIFont fontWithName:@"helvetica" size:12]; //字体和大小设置
LY_Text.textColor = [UIColor redColor]; //设置字体的颜色
LY_Text.clearButtonMode = UITextFieldViewModeWhileEditing; //清空功能x
LY_Text.returnKeyType = UIReturnKeyDone; //键盘有done
LY_Text.secureTextEntry = YES; //密码输入时
LY_Text.delegate = self; //托管

}

//消息弹出提示
void show(id formatstring)
{

UIAlertView *Point = [[[UIAlertView alloc] initWithTitle:nil message:formatstring delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[Point show];
}

//UITextField输入长度限制
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location >= 8)
{
show(@"密码长度有误");
return NO;
}
return YES;

}

 

//点击软键盘上"Done"这个键,键盘自动隐藏
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

 

from:http://diandianyangsamllplace.diandian.com/post/2011-08-11/3745463

 

iPhone UITextField - Change placeholder text color

from:http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color

[self.myTextField setValue:[UIColor darkGrayColor]
forKeyPath:@"_placeholderLabel.textColor"];

 

You can override drawPlaceholderInRect:(CGRect)rect as such to manually render the placeholder text:

-(void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}

转载于:https://www.cnblogs.com/I-am-fine/archive/2012/08/31/2665208.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值