Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does UIButton.setTitle change the font size?

Tags:

ios

swift

I'm building an iOS app for a class, and I'm following along some instructions. The Edit button is connected to toggleEditingMode, but when I change the text, for some reason the font size is reset to 17, even though it's 30 in the storyboard editor.

I've tried changing the font size, if I print the current font size after executing setTitle it still says 30, so it seems like it must be happening outside of setTitle, but it only triggers if I use setTitle. Help!

class ItemsViewController: UITableViewController {
    var choreStore: ChoreStore!
    var roommateStore: RoommateStore!
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return choreStore.allChores.count
    }
        
    override func tableView(_ tableView: UITableView,
            cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        // Create an instance of UITableViewCell with default appearance
        let cell = tableView.dequeueReusableCell(withIdentifier: "chore", for: indexPath) as! ChoreCell

        // Set the text on the cell with the description of the item
        // that is at the nth index of items, where n = row this cell
        // will appear in on the table view
        let chore = choreStore.allChores[indexPath.row]

        cell.title?.text = chore.title
        cell.turn?.text = "\(chore.whoseTurn())'s Turn"
        cell.completed?.text = chore.completedString()
        cell.completed?.textColor = chore.isOverdue ? .red : .black

        return cell
    }
    
    @IBAction func addNewItem(_ sender: UIButton) {

    }

    @IBAction func toggleEditingMode(_ sender: UIButton) {
        setEditing(!isEditing, animated: true)
        sender.setTitle(isEditing ? "Done" : "Edit", for: .normal)
    }
}
like image 704
Lexi Reinsborough Avatar asked Dec 05 '25 20:12

Lexi Reinsborough


1 Answers

Change your button style to Default:

Setting style

like image 157
Tulio Parreiras Avatar answered Dec 08 '25 12:12

Tulio Parreiras