UITextField 占位符RectForBounds

发布于 2024-10-06 20:38:34 字数 141 浏览 1 评论 0原文

我想创建一个 UITextField,其中占位符向左对齐,文本向中心对齐。我搜索了一下,发现 placeholderRectForBounds: 函数苹果文档说如果你想覆盖,但没有说如何覆盖?我尝试对 UITextField 进行分类,但没有成功。有人有想法吗? 谢谢

I want to create a UITextField with the placeholder aligned to left and the text is aligned to center. I search a bit and I found placeholderRectForBounds: function the apple documents says override if you want to but doesnt say how? I tried categorize the UITextField however It wasnt a success. any one has an idea?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朕就是辣么酷 2024-10-13 20:38:34

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

当您开始在文本字段上输入内容时,将调用此委托

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

At default set the text alignment as left.

When you start typing on the textfield this delegate will be called

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

This delegate will be called when you focus out of textfield

- (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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文