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)
    }
}

效果

相关推荐
游戏开发爱好者813 小时前
TCP 抓包分析:tcp抓包工具、 iOS/HTTPS 流量解析全流程
网络协议·tcp/ip·ios·小程序·https·uni-app·iphone
天堂罗恋歌14 小时前
CocoaPods 安装 Masonry 库时出现的网络连接问题处理
ios·iphone·xcode·cocoapods·app store
2501_9160088914 小时前
iOS 26 软件性能测试全流程,启动渲染资源压力对比与优化策略
android·macos·ios·小程序·uni-app·cocoa·iphone
00后程序员张15 小时前
iOS 26 兼容测试实战,机型兼容、SwiftUI 兼容性改动
android·ios·小程序·uni-app·swiftui·cocoa·iphone
2501_9151063216 小时前
iOS 可分发是已经上架了吗?深入解析应用分发状态、ipa 文件上传、TestFlight 测试与 App Store 审核流程
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
HTTPS 抓包乱码怎么办?原因剖析、排查步骤与实战工具对策(HTTPS 抓包乱码、gzipbrotli、TLS 解密、iOS 抓包)
android·ios·小程序·https·uni-app·iphone·webview
2501_916008891 天前
HTTPS 双向认证抓包实战,原理、难点、工具与可操作的排查流程
网络协议·http·ios·小程序·https·uni-app·iphone
2501_915106321 天前
HTTPS 能抓包吗?实战答案与逐步可行方案(HTTPS 抓包原理、证书Pinning双向认证应对、工具对比)
网络协议·http·ios·小程序·https·uni-app·iphone
游戏开发爱好者81 天前
App HTTPS 抓包实战,原理、常见问题与可行工具路线(开发 测试 安全 角度)
网络协议·安全·ios·小程序·https·uni-app·iphone
2501_915106321 天前
App HTTPS 抓包实战指南,原理、常见阻碍、逐步排查与工具组合
网络协议·http·ios·小程序·https·uni-app·iphone