右对齐 UISearchbar 占位符

问题描述 投票:0回答:3

此代码曾经有效,但在ios 10之后它已停止运行:

UITextField *searchTextField = [_searchBar valueForKey:@"_searchField"];
searchTextField.textAlignment = NSTextAlignmentRight

我尝试了段落和attributePlaceholder,但占位符总是左对齐。该错误出现在 xcode 7 和 8 中。我该如何解决这个问题?

ios objective-c iphone uisearchbar ios10
3个回答
9
投票

也许这很长时间了,这是解决方案

斯威夫特

searchBar.semanticContentAttribute = .forceRightToLeft

1
投票

如果您需要进行此类自定义,请不要使用

UISearchBar
。您必须使用
UITextField
UIImageView
自己制作,并响应
delegate
呼叫。


0
投票

无论您是否在 NavigationBar 中使用 searchBar,此解决方案都适用于两种情况:

searchBar.searchTextField.semanticContentAttribute = .forceRightToLeft
searchBar.searchTextField.textAlignment = .right
© www.soinside.com 2019 - 2024. All rights reserved.