为什么 UIButton.setTitle 会改变字体大小?

Lex*_*ugh 15 ios swift

我正在为课程构建一个 iOS 应用程序,并且正在按照一些说明进行操作。“编辑”按钮连接到toggleEditingMode,但是当我更改文本时,由于某种原因,字体大小被重置为 17,即使在故事板编辑器中它是 30。

我尝试过更改字体大小,如果我在执行 setTitle 后打印当前字体大小,它仍然显示 30,所以看起来它一定发生在 setTitle 之外,但只有在我使用 setTitle 时才会触发。帮助!

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)
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 26

将按钮样式更改为默认:

设置风格