2016-06-02 6 views
0

검색 창에 첫 번째 프롬프트 메시지를 한 색상으로 표시하려고합니다. 사용자가 텍스트를 입력하자마자 프롬프트를 제거하고 사용자가 입력하는 텍스트의 색을 변경합니다. 내가 사용자를 통보받을 때검색 표시 줄이 표시된 상태에서 텍스트 색상을 변경할 수 있습니까?

UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.lightGrayColor() 

그런 다음 프롬프트 메시지의 초기 색상을 설정하려면이 옵션을 사용하고

내가 색상을 변경하려고 텍스트를 입력하기 시작했다

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) 
{ 
    appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.blackColor() 
    ... 

검색 표시 줄이 표시되기 전에 색을 설정할 수 있지만 이미 표시되어있는 것은 아닙니다. 아무도 이것에 대한 해결 방법을 알고 있습니까?

초기 프롬프트 메시지를 설정하는

답변

-3

사용 UISearchBarplaceholder 특성 (검색 바 UISearchController를 통해 자동으로 표시 &를 생성되는). UISearchBar은 기본적으로 사용자가 입력 한 텍스트의 텍스트 색과 완전히 독립적 인 색을 70 % 회색으로 설정합니다.

var searchBar = UISearchBar() 
// This message will be set to a gray color by default 
// UISearchBar will automatically clear it once the user starts typing 
searchBar.placeholder = "Enter a message here..." 
// This text color will be applied to the text that the user types 
searchBar.textColor = UIColor.blackColor() 
+0

UISearchBar에는 'textColor'라는 속성이 없습니다. –

관련 문제