UITextField 基本設置

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

一、UILabel的基本設置iphone

二、UITextFiel的基本設置ide

三、設置UITextFiel輸入長度的限制post

四、彈出提示消息字體

五、UITextFiel輸入時自動隱藏鍵盤
ui

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

}orm

//點擊軟鍵盤上"Done"這個鍵,鍵盤自動隱藏
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}ip

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

iPhone UITextField - Change placeholder text colorstring

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]];
}

相關文章
相關標籤/搜索