iOS16適配指南之UIImage

  • SF Symbols 中增加了新的類別 Variable,其中的圖標支持可變渲染。
  • UIImage 相應(yīng)地增加了新的構(gòu)造函數(shù)支持可變渲染。
import Combine
import UIKit

class ViewController: UIViewController {
    // 可變色度
    lazy var variable: Double = 0 {
        didSet {
            // 新的構(gòu)造函數(shù),支持可變渲染
            let image = UIImage(systemName: "touchid", variableValue: variable, configuration: symbolConfig)
            imageView.image = image
        }
    }
    // 配置圖標的渲染顏色
    let symbolConfig = UIImage.SymbolConfiguration(paletteColors: [.systemTeal, .systemGreen])
    var cancellable: [AnyCancellable] = []
    // Combine定時器
    let timer = Timer.publish(every: 0.2, on: .main, in: .common)
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView(image: UIImage(systemName: "touchid", variableValue: 0, configuration: symbolConfig))
        imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
        imageView.contentMode = .scaleAspectFit
        imageView.center = view.center
        return imageView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(imageView)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        // 動態(tài)調(diào)整Variable圖標
        timer
            .autoconnect()
            .sink { [weak self] _ in
                guard let self = self else { return }
                switch self.variable {
                case 0:
                    self.variable = 0.2
                case 0.2:
                    self.variable = 0.4
                case 0.4:
                    self.variable = 0.6
                case 0.6:
                    self.variable = 0.8
                case 0.8:
                    self.variable = 1.0
                case 1.0:
                    self.variable = 0.9
                case 0.9:
                    self.variable = 0.7
                case 0.7:
                    self.variable = 0.5
                case 0.5:
                    self.variable = 0.3
                case 0.3:
                    self.variable = 0.1
                default:
                    self.variable = 0
                }
            }
            .store(in: &cancellable)
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • iOS 16 真機調(diào)試時需要在設(shè)備的設(shè)置 —> 隱私與安全 —> 開發(fā)者模式 中打開開發(fā)者模式。 新增 UICal...
    YungFan閱讀 10,256評論 17 23
  • 開發(fā)小知識(一)[http://m.itdecent.cn/p/5a4ba3c165b9] 開發(fā)小知識(二)...
    ZhengYaWei閱讀 10,294評論 11 140
  • UIKit 1.UIView 和 CALayer 是什么關(guān)系? UIView 繼承 UIResponder,而 U...
    Sephiroth_Ma閱讀 2,451評論 0 25
  • 做這個的初心是希望能鞏固自己的基礎(chǔ)知識,也通過這種方式檢查自己知識的缺失點。目前還不完善,后續(xù)會根據(jù)時間不斷更正和...
    lp_lp閱讀 37,379評論 7 147
  • 1.網(wǎng)絡(luò) 1.網(wǎng)絡(luò)七層協(xié)議有哪些? 物理層:主要功能:傳輸比特流;典型設(shè)備:集線器、中繼器;典型協(xié)議標準和應(yīng)用:V...
    _我和你一樣閱讀 3,911評論 1 38

友情鏈接更多精彩內(nèi)容