2010-12-06 51 views
0

我想创建一个UITextField,占位符左对齐,文本对齐居中。我搜索了一下,我发现placeholderRectForBounds:函数苹果文件说覆盖如果你想但不说如何?我试着对UITextField进行分类,但它并不成功。任何人有一个想法? 谢谢UITextField placeholderRectForBounds

+0

究竟什么是你的问题的此委托将被调用?你是否问如何让'UITextField`使用左对齐,当它只有占位符文本时,并且当用户输入文本时切换到居中对齐? – 2010-12-06 08:09:49

+0

我想设置textAligment:到中心,但我也希望占位符文本出现在框的左侧。 – cekisakurek 2010-12-06 14:23:21

回答

0

默认情况下,将文本对齐方式设置为左侧。

当您开始键入的文本框此委托将被称为

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    //here again set the alignment value to center 
    textField.textAlignment=UITextAlignmentCenter; 
} 

当你专注了文本框

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    //Here check text in the textfield. if its nill set alignment as left. 
    //Becoz if there is no text in textfield placeholder will be shown. 
}