You need to enable JavaScript to run this app. Swift 5:导航栏右侧自定义UIBarButtonItem显示不适配问题求助
优惠活动
大模型
产品
解决方案
定价
更多

Swift 5:导航栏右侧自定义UIBarButtonItem显示不适配问题求助

导航栏自定义右侧按钮适配异常

问题背景

  • 已准备对应功能按钮的设计素材图
  • 目标是将自定义按钮设置为导航栏rightBarButtonItem,但目前显示效果与导航栏预留区域不适配,同时已附上真机实际运行的效果截图用于问题排查

现有实现代码

let button = UIButton(type: .custom)
button.setImage(UIImage (named: "Group 4"), for: .normal)
button.frame = CGRect(x: 0.0, y: 0.0, width: 35, height: 35)
//button.addTarget(target, action: nil, for: .touchUpInside)
let barButtonItem = UIBarButtonItem(customView: button)
self.navigationItem.rightBarButtonItem = barButtonItem

求助诉求

恳请大家帮忙提供该适配问题的解决方案。


内容的提问来源于stack exchange,提问作者Ngo Viet Toan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.02 08:36:03