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

Xcode 16中@IBInspectable属性无法在xib编辑器中显示求助

Xcode升级后@IBInspectable属性不显示的解决办法
  • 清理项目缓存

    • 按下 Cmd + Shift + K 清理项目,再用 Cmd + Option + Shift + K 清理构建文件夹
    • 完全退出Xcode和关联的模拟器后重新打开
  • 检查代码实现细节

    • 确保@IBInspectable属性是Interface Builder支持的类型(CGFloat、UIColor、NSString、Bool等),比如testCornerRadius的正确声明示例:
      @IBInspectable var testCornerRadius: CGFloat = 0.0 {
          didSet {
              layer.cornerRadius = testCornerRadius
              layer.masksToBounds = true
          }
      }
      
    • 若通过扩展添加属性,需确保扩展的类是UIKit控件的直接子类,且属性添加@objc标记(Swift属性需暴露给OC才能被IB识别):
      extension UIView {
          @IBInspectable @objc var testCornerRadius: CGFloat {
              get { layer.cornerRadius }
              set {
                  layer.cornerRadius = newValue
                  layer.masksToBounds = true
              }
          }
      }
      
  • 检查XIB配置

    • 在XIB中选中目标控件,打开Identity Inspector,确认Class字段选择的是你添加了@IBInspectable的类(而非父类)
    • 切换到Attributes Inspector,拉到面板最底部,自定义Inspectable属性通常会放在单独的区域,注意是否被折叠
  • 重置Xcode偏好设置

    • 关闭Xcode,在终端执行命令:defaults delete com.apple.dt.Xcode
    • 重新打开Xcode并加载项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 10:33:14