美文网首页iOS17适配指南
iOS17适配指南之UIImageView、UIButton

iOS17适配指南之UIImageView、UIButton

作者: YungFan | 来源:发表于2023-06-14 08:20 被阅读0次

    UIImageView

    • 支持显示 HDR 图片。
    import UIKit
    
    class ViewController: UIViewController {
        lazy var imageView: UIImageView = {
            let imageView = UIImageView(image: UIImage(named: "hdr.png"))
            imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
            imageView.contentMode = .scaleAspectFit
            imageView.center = view.center
            // 支持HDR图片
            imageView.preferredImageDynamicRange = .constrainedHigh
            return imageView
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            view.addSubview(imageView)
        }
    }
    
    • Symbol Animations 新特性使得 SF Symbols 中的图标可以呈现丰富多彩的动画。通过addSymbolEffect()方法增加动画效果,removeSymbolEffect()removeAllSymbolEffects()方法移除动画效果。
    import UIKit
    
    class ViewController: UIViewController {
        lazy var imageView: UIImageView = {
            let imageView = UIImageView(image: UIImage(systemName: "touchid"))
            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)
            imageView.addSymbolEffect(.variableColor.reversing, options: .repeat(3), animated: true) { context in
                if context.isFinished {
                    print("动画完成")
                }
            }
        }
    
        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            imageView.removeSymbolEffect(ofType: .variableColor.reversing)
            // imageView.removeAllSymbolEffects()
        }
    }
    

    UIButton

    Symbol Animations 新特性使得按钮中使用的 SF Symbols 图标也可以呈现动画。

    import UIKit
    
    class ViewController: UIViewController {
        lazy var button1: UIButton = {
            let button = UIButton(frame: CGRect(x: 100, y: 0, width: 100, height: 60))
            button.setImage(UIImage(systemName: "heart"), for: .normal)
            // 开启Symbol Animations
            button.isSymbolAnimationEnabled = true
            return button
        }()
        lazy var button2: UIButton = {
            let actionHandler = UIAction { _ in
            }
            actionHandler.image = UIImage(systemName: "plus")
            let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 60), primaryAction: actionHandler)
            button.isSymbolAnimationEnabled = true
            return button
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            view.addSubview(button1)
            view.addSubview(button2)
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS17适配指南之UIImageView、UIButton

        本文链接:https://www.haomeiwen.com/subject/xfvhydtx.html