ThatMan
ThatMan

Reputation: 165

How can I change text size of button?

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

Answers (3)

oveyamo
oveyamo

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

Fogmeister
Fogmeister

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

Hima
Hima

Reputation: 1247

Set the titleLabel.font property for your button.

playAgain.titleLabel!.font =  UIFont(name: "Helvetica", size: 20)

Upvotes: 1

Related Questions