iOS16適配指南之UIImage

  • SF Symbols 中增加了新的類別 Variable,其中的圖標(biāo)支持可變渲染。
  • 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
        }
    }
    // 配置圖標(biāo)的渲染顏色
    let symbolConfig = UIImage.SymbolConfiguration(paletteColors: [.systemTeal, .systemGreen])
    var cancellable: [AnyCancellable] = []
    // Combine定時(shí)器
    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?) {
        // 動(dòng)態(tài)調(diào)整Variable圖標(biāo)
        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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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

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