Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Search Bar placeholder text font in Swift

Tags:

I am trying to change the font of the placeholder text in the search bar within my Search Display Controller. I was looking at some examples and I tried to implement them but as they are in Objective-C, I wasn't able to find any that I could get to work.

For example, I tried this one:

UITextField *textField = [[searchBar subviews] objectAtIndex:1];  [textField setFont:[UIFont fontWithName:@"Helvetica" size:40]]; 

But I was unable to get past var textField: UITextField = UISearchBar

Any ideas?

like image 887
user3746428 Avatar asked Oct 18 '14 16:10

user3746428


People also ask

How do I change text font in Swift?

SwiftUI lets you customize Text by applying a . font() modifier. The default iOS font is called San Francisco and if you don't explicitly change it, then all of your text will have the default iOS look. Some other options of standard fonts include: title, headline, subheadline, body, callout, caption or footnote.

How do I change the font size on a button title in Swift?

Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

 //SearchBar Text     let textFieldInsideUISearchBar = dashBoardSearchBar.valueForKey("searchField") as? UITextField textFieldInsideUISearchBar?.textColor = UIColor.whiteColor()  //SearchBar Placeholder          let textFieldInsideUISearchBarLabel = textFieldInsideUISearchBar!.valueForKey("placeholderLabel") as? UILabel textFieldInsideUISearchBarLabel?.textColor = UIColor.whiteColor() 
like image 87
Alvin George Avatar answered Oct 04 '22 09:10

Alvin George