Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton font size isn't changing

Tags:

uikit

swift

private func updateViewFromModel() {
    for index in cardButtons.indices {
        let button = cardButtons[index]
        let card = game.cards[index]
        if card.isFaceUp {
            button.setTitle(emoji(for: card), for: .normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 50)
            button.backgroundColor = .lightGray
        } else {
            button.setTitle("", for: .normal)
            button.backgroundColor = card.isMatched ? .clear : .systemIndigo
        }
        
    }
}

Can anyone tell me what's wrong with this code? title in IB is empty. I successfully set the title. but font size isn't changing.

like image 877
isifip Avatar asked Nov 17 '25 15:11

isifip


1 Answers

In Xcode 13 ,UIButton has four type are Plain,Grain,Tinted,Filled .When you create a button in storyboard , button type automatically set with Plain that means new UIButton configurations is on. If you want to old behaviour , you must set style plain to default.

Or , If you want one of the style above . You need to set font like

button.configuration?.titleTextAttributesTransformer =
   UIConfigurationTextAttributesTransformer { incoming in
     var outgoing = incoming
     outgoing.font = UIFont.systemFont(ofSize: 50)
     return outgoing
 }
like image 182
Omer Tekbiyik Avatar answered Nov 20 '25 07:11

Omer Tekbiyik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!