我想创建一个UITextField,其中占位符左对齐,文本居中对齐。我搜索了一下,我找到了placeholderRectForBounds: function,苹果文档说,如果你想重写,但没有说怎么做?我试着对UITextField进行分类,但是没有成功。有谁有主意吗?谢谢
发布于 2010-12-06 22:32:26
默认情况下,将文本对齐方式设置为左对齐。
当您开始在文本字段中键入内容时,将调用此委托
- (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.
}https://stackoverflow.com/questions/4364192
复制相似问题