iOS26适配指南之Liquid Glass App Icon

介绍

  • Xcode 26 内置了 Icon Composer 应用,能够创建.icon的设计文件,可以让开发者与设计师创建符合 "Liquid Glass" 风格的全平台(iOS、macOS、 watchOS) App Icon。
  • 通过 Icon Composer 将设计好的.icon文件导出,然后导入 iOS 项目,在项目设置中选择该文件作为 App Icon,勾选Include all app icon assets,即可作为 App 的图标使用。

案例:动态切换图标

  • 代码。
swift 复制代码
import UIKit

enum AppIcon: String, CaseIterable {
    case defaultIcon
    case redIcon
    case greenIcon
    case blueIcon

    // icon文件的名称
    var iconName: String? {
        switch self {
        case .defaultIcon:
            return nil // 默认图标
        case .redIcon:
            return "RedIcon" // 第1个icon
        case .greenIcon:
            return "GreenIcon" // 第2个icon
        case .blueIcon:
            return "BlueIcon" // 第3个icon
        }
    }
}

class ViewController: UIViewController {
    lazy var segmentedControl: UISegmentedControl = {
        let segmentedControl = UISegmentedControl(items: AppIcon.allCases.map { $0.rawValue })
        segmentedControl.selectedSegmentIndex = 0
        segmentedControl.translatesAutoresizingMaskIntoConstraints = false
        segmentedControl.addTarget(self, action: #selector(valueChanged), for: .valueChanged)
        return segmentedControl
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(segmentedControl)
        
        NSLayoutConstraint.activate([
            segmentedControl.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            segmentedControl.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            segmentedControl.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor, constant: 20),
            segmentedControl.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor, constant: -20)
        ])
    }

    @objc func valueChanged(_ sender: UISegmentedControl) {
        let selectedIndex = sender.selectedSegmentIndex
        let selectedIcon = AppIcon.allCases[selectedIndex]
        if UIApplication.shared.supportsAlternateIcons {
            UIApplication.shared.setAlternateIconName(selectedIcon.iconName) { error in
                if error != nil {
                    print(error?.localizedDescription)
                } else {
                    print("切换App图标成功")
                }
            }
        } else {
            print("不支持切换App图标")
        }
    }
}
  • 效果。
相关推荐
传奇开心果编程几秒前
【SwiftUI入门练中学】第7课 动画与手势:让界面更灵动
学习·macos·ui·ios·swiftui·swift
知潮网2 小时前
发售刚十天,9999 元的 iPhone 18 Pro 解锁就重启
ios·iphone
2501_916007476 小时前
苹果应用商店App Store上架费用标准及原因解析
android·ios·小程序·https·uni-app·iphone·webview
传奇开心果编程18 小时前
【SwiftUI娓娓道来】第3课:让界面活起来——交互与动画指南
学习·macos·ui·ios·swiftui·swift
可乐鸡翅yeah_18 小时前
新手梳理:M3U8 线上问题,哪些是前端锅,哪些是后端锅
前端·ios·音视频·实时音视频·m3u8·音视频在线播放
00后程序员张1 天前
苹果App Store上架指南:费用、原理与步骤详解
android·ios·小程序·https·uni-app·iphone·webview
黑科技iOS上架1 天前
Unity3D游戏过审App Store4.3机审实战
ios·审核·ios混淆·执行程序差异化
用户38034165882971 天前
控制中心一键后台录音:我被自己的 Spike 骗了两次
ios·swift
Crazy_MT1 天前
App 可能不再是入口:从 iOS 27 快捷指令看苹果的 AI Agent 野心
人工智能·ios·apple
Maple9961 天前
Firebase iOS SDK 重大事故:一个 nil key 如何让全球 App 集体崩溃
ios