Home > Net >  How to change Weight property of UIButton title in a custom UITableViewCell?
How to change Weight property of UIButton title in a custom UITableViewCell?

Time:11-19

I have a custom cell that has three buttons, that when one of them is pressed, its title weight changes to bold and the font size of the other two buttons gets shrunked.

enter image description here

As it is shown above, while the titles of the other buttons do change their font size, the weight of the title of the pressed button does not seem to change at all. What am I missing? Thanks.

The code of the custom cell:

import UIKit

class SymptomTableViewCell: UITableViewCell {
    
    @IBOutlet weak var severeButton: UIButton!
    @IBOutlet weak var moderateButton: UIButton!
    @IBOutlet weak var lowButton: UIButton!
    
    var selectedButton = UIButton()

    var buttons = [UIButton]()

    override func awakeFromNib() {
        super.awakeFromNib()
        buttons = [severeButton, moderateButton, lowButton]
    }
    
    @IBAction func rateButtonPressed(_ sender: UIButton) {
        if sender != selectedButton {
            selectedButton = sender
            for button in buttons {
                if button != selectedButton {
                    button.titleLabel?.font = .systemFont(ofSize: 12)
                }
            }
            selectedButton.titleLabel?.font = .boldSystemFont(ofSize: 16)
        }
    }
}

CodePudding user response:

Changing button style from plain to default worked.

  • Related