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图标")
        }
    }
}
  • 效果。
相关推荐
楚轩努力变强6 小时前
iOS 自动化环境配置指南 (Appium + WebDriverAgent)
javascript·学习·macos·ios·appium·自动化
游戏开发爱好者81 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
黑码哥1 天前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
2501_915106321 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
熊猫钓鱼>_>1 天前
移动端开发技术选型报告:三足鼎立时代的开发者指南(2026年2月)
android·人工智能·ios·app·鸿蒙·cpu·移动端
徐同保2 天前
通过ip访问nginx的服务时,被第一个server重定向了,通过设置default_server解决这个问题
ios·iphone
2501_915918412 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
夏幻灵3 天前
HTTPS全面解析:原理、加密机制与证书体
ios·iphone