日々精進

新しく学んだことを書き留めていきます

UISearchBarのplaceholderのフォントを変更する

UISearchBarのplaceholderのフォントは変更できないらしい。
ので、placeholder用UILabelを作ってUISearchBarのSubviewとして追加し、UISearchBarDelegateのsearchBarTextDidBeginEditingとsearchBarTextDidEndEditingの中でラベルを表示・非表示することでplaceholderっぽく見せるようにした。
標準のコンポーネントはデザインを変更しようとすると意外と柔軟性がないな。。
参考:iphone - UISearchBar Placeholder besides another Text - Stack Overflow