I'm trying to add a pull to refresh to my table view controller, so I have worked on the functionality and then I'm working on the layout. The functionality works perfect but I have some issues related to the layout, I want to change the font and font color of the title. I changed them on the Attribute of the refresh controller on the storyboard, but each time I run the project all my settings are back to default. So, I have tried to work on them using the code, and now I'm able to change the background and the tintColor, but I'm not able to change the font and color. Could you please help me, and this is my code:
refresh.backgroundColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)
refresh.tintColor = UIColor(red: 155/255, green: 155/255, blue: 154/255, alpha: 1)
var label:NSAttributedString = NSAttributedString(string: "Refresh!!!")
refresh.attributedTitle = label
Thanks,
I see that this question is pretty old but just in case someone else stumbles upon this when searching for the answer here's a way.
The colour is part of the attributed string and is set through the attributes dictionary.
let attributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
let attributedTitle = NSAttributedString(string: "title", attributes: attributes)
refreshControl.attributedTitle = attributedTitle
The same is true for the font.
[NSFontAttributeName: UIFont(name: fontName, size: size)]
Swift 4:
let attributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing please wait", attributes: attributes)
Swift 3:
let attributes = [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 12)]
refreshControl.attributedTitle = NSAttributedString(string: "Test text", attributes: attributes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With