B站學習斯坦福大學Swift 語言教程 iOS11 開發【第一集】踩到的幾個坑(XCode 13.2.1版本)

1. 在Xcode 13.2.1 中,找不到從哪裏拖拽添加button控件

Xcode13起,添加UI控件需要點擊右上方的➕號

2. button的title屬性設置成ghost的emoji後,無法改變字體大小

需要把button的Style屬性由plain更改爲default

3. button.currentTitle 無法返回button的實際currentTitle,而是固定值Button

原因是我把button的Title屬性改爲Attributed了,改回plain即可獲取被按下button的currentTitle。

import UIKit

class ViewController: UIViewController {


    @IBAction func touchCard(_ sender: UIButton) {
        flipCard(withEmoji: "👻", on: sender)
    }
    
    func flipCard(withEmoji emoji: String, on button: UIButton){
        print("Log: " + button.currentTitle.unsafelyUnwrapped)
        if button.currentTitle == emoji{
            button.setTitle("", for: UIControl.State.normal)
            button.backgroundColor = UIColor.orange
        }else{
            button.setTitle(emoji, for: UIControl.State.normal)
            button.backgroundColor = UIColor.white
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章