Baker2795 Baker2795 - 9 months ago 77
Swift Question

How to change button font when touch up outside?

So I am trying to change the font of a button when it is pressed and then revert the font when the user touches up inside of another button. Changing the font when a user touches up inside currently works but I created an outlet from storyboard for a touchUpOutside action and tried to recycle the code and it is not working.

@IBAction func touchUpInside(_ sender: AnyObject) {
sender.titleLabel?!.font = UIFont(name: "Futura-CondensedExtraBold", size: 25)
@IBAction func touchUpOutside(_ sender: AnyObject) {
sender.titleLabel?.font = UIFont(name: "Futura-Medium", size: 22)

Answer Source

Revert font for button1 when pressing button2

If this is the answer you were looking for don't forget to except the answer.

//Button 1 as outlet.
@IBOutlet weak var button1Outlet: UIButton!

//Button 1 as touchUpInside.
@IBAction func button1(_ sender: AnyObject) {
    sender.titleLabel?!.font = UIFont(name: "Futura-CondensedExtraBold", size: 25)

//Button 2 as touchUpInside.
@IBAction func button2(_ sender: AnyObject) {

//Referenceing button 1 outlet.
    button1Outlet.titleLabel?.font = UIFont.systemFont(ofSize: 15.0)