gpt4 book ai didi

ios - IBInspectable UIView 属性

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:26 24 4
gpt4 key购买 nike

我可以让我的 UIView @property 可检查吗?

@interface Superview : UIView 
@property (nonatomic, weak, readonly) IBInspectable UIButton *stopButton;
@property (nonatomic, weak, readonly) IBInspectable PKCircleProgressView *circleProgressView;
@end

我已经创建了一个可设计的 View PKCircleProgressView,我希望它可以从 IB 进行编辑。我还创建了另一个可设计的 View ,其中包含 PKCircleProgressView 作为 subview ,我希望它也可以编辑。

如果我在 IB 中使用 Superview,是否有任何方法可以编辑 circleProgressView 的属性?

我只有一个想法,即为两个 View 创建一个通用协议(protocol),并实现如下方法:

- (void)setProgress:(CGFloat)progress {
self.circleProgressView.progress = progress;
}

但要对每个属性都做到这一点并不容易,尤其是当我想创建另一个包含我的 super View 的 View 时。

最佳答案

IBInspectable 不支持 UIView 或其子类型。它支持简单的值。

如果您的自定义进度 View 是 IBDesignable,为什么不将它的属性(如半径和前景色)设置为 IBInspectable 并在界面构建器中选择进度 View 并更改进度 View 的属性?

如果您创建一个 IBDesignable super View ,您可以使用类似装饰器模式的东西来公开它的按钮和进度 View 的可检查属性。

Apple's Documentation

关于ios - IBInspectable UIView 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30548476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com