Reputation: 165
I need change text's size. How can I do it? Here is my code:
let playAgain: UIButton = UIButton(frame: CGRectMake(140, 400, 100, 50))
playAgain.setTitle("Play Again", forState: UIControlState.Normal)
playAgain.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
playAgain.tag = 1
self.view!.addSubview(playAgain)
Upvotes: 0
Views: 2512
Reputation: 91
If you want to change just the size of the font while keeping the font as it is, you may use this :
playAgain.titleLabel.font = UIFont(name: playAgain.titleLabel.font.fontName, size: /*whatever size you like*/ )
Upvotes: 1
Reputation: 77621
To change the font of a button you have to access the titleLabel
property.
playAgain.titleLabel!.font = //... the font you want to use
This is explained in the docs for UIButton
.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/
Upvotes: 0
Reputation: 1247
Set the titleLabel.font
property for your button.
playAgain.titleLabel!.font = UIFont(name: "Helvetica", size: 20)
Upvotes: 1