You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI技术疑问:为何.shadow无法显示.secondarySystemBackground颜色?

问题原因

UIColor.secondarySystemBackground是苹果设计的次要背景色,它的核心作用是和主背景色做弱区分,本身和主背景色(浅色模式白、深色模式黑)的对比度极低。而阴影是绘制在视图下方的,和当前视图所在的背景色几乎完全一致,所以肉眼根本看不到。

解决方案
  • 给颜色叠加透明度,降低和背景的相似度:
    Rectangle().shadow(color: Color(UIColor.secondarySystemBackground).opacity(0.5), radius: 7)
    
  • 改用系统专为阴影/分隔场景设计的灰度色,比如systemGray5,这类颜色本身就具备合适的对比度:
    Rectangle().shadow(color: Color(UIColor.systemGray5), radius: 7)
    
  • 调整阴影的偏移量,让阴影从视图下方“露”出来,和背景形成视觉差:
    Rectangle().shadow(color: Color(UIColor.secondarySystemBackground), radius: 7, x: 2, y: 2)
    

内容的提问来源于stack exchange,提问作者theCoder1243323543

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 14:27:31