iOS26适配指南之UINavigationController

UINavigationItem

  • 增加了类型为UIString?subtitle,用于设置标准模式下的导航栏的副标题。
  • 增加了类型为UIString?largeTitlelargeSubtitle属性,用于设置 prefersLargeTitles 模式下导航栏的标题与副标题。
  • 增加了类型为UIView?subtitleViewlargeSubtitleView属性,用于设置标准与 prefersLargeTitles 模式下导航栏的副标题视图。

案例

swift 复制代码
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.navigationBar.prefersLargeTitles = true
        // iOS26新增
        navigationItem.largeTitle = "导航"
        navigationItem.largeSubtitle = "子标题"
    }
}

效果

UIBarButtonItem

  • 增加了badge属性,用于设置角标。
  • 增加了prominent样式,用于凸显。
  • 增加了fixedSpace()flexibleSpace()方法,用于调整彼此之间的间距。

案例

swift 复制代码
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .systemGreen

        let barButtonItemOne = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(handleEvent))
        let barButtonItemTwo = UIBarButtonItem(barButtonSystemItem: .bookmarks, target: self, action: #selector(handleEvent))
        let barButtonItemThree = UIBarButtonItem(barButtonSystemItem: .camera, target: self, action: #selector(handleEvent))
        let barButtonItemFour = UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(handleEvent))
        // iOS26新增
        barButtonItemOne.badge = .count(10)
        // iOS26新增
        barButtonItemFour.style = .prominent
        // iOS26新增
        let fixedSpace = UIBarButtonItem.fixedSpace(20)
        let flexibleSpace = UIBarButtonItem.flexibleSpace()
        navigationItem.rightBarButtonItems = [barButtonItemOne]
        navigationController?.isToolbarHidden = false
        toolbarItems = [barButtonItemTwo, fixedSpace, barButtonItemThree, flexibleSpace, barButtonItemFour]
    }

    @objc func handleEvent(_ sender: UIBarButtonItem) {
        view.backgroundColor = .init(red: .random(in: 0 ... 1), green: .random(in: 0 ... 1), blue: .random(in: 0 ... 1), alpha: 1.0)
    }
}

效果

相关推荐
大熊猫侯佩17 小时前
黑衣人档案:用 Apple Foundation Models + SwiftUI 打造 AI 聊天机器人全攻略
ios·swiftui·ai编程
大熊猫侯佩17 小时前
侠客行・iOS 26 Liquid Glass TabBar 破阵记
ios·swiftui·swift
2501_9160074719 小时前
手机使用过的痕迹能查到吗?完整查询指南与步骤
android·ios·智能手机·小程序·uni-app·iphone·webview
從南走到北20 小时前
JAVA国际版同城外卖跑腿团购到店跑腿多合一APP系统源码支持Android+IOS+H5
android·java·ios·微信小程序·小程序
alengan1 天前
苹果企业签名流程
ios·iphone
Digitally1 天前
如何在Mac上同步iPhone短信
macos·ios·iphone
2501_915106321 天前
App HTTPS 抓包 工程化排查与工具组合实战
网络协议·ios·小程序·https·uni-app·php·iphone
2501_916008891 天前
金融类 App 加密加固方法,多工具组合的工程化实践(金融级别/IPA 加固/无源码落地/Ipa Guard + 流水线)
android·ios·金融·小程序·uni-app·iphone·webview
2501_915921432 天前
Fastlane 结合 开心上架(Appuploader)命令行版本实现跨平台上传发布 iOS App 免 Mac 自动化上架实战全解析
android·macos·ios·小程序·uni-app·自动化·iphone
游戏开发爱好者82 天前
iOS 上架要求全解析,App Store 审核标准、开发者准备事项与开心上架(Appuploader)跨平台免 Mac 实战指南
android·macos·ios·小程序·uni-app·iphone·webview