gpt4 book ai didi

ios - 是否可以在没有继承的情况下覆盖类上的 drawRect?

转载 作者:行者123 更新时间:2023-11-29 13:35:33 27 4
gpt4 key购买 nike

我需要知道是否可以全局覆盖 UI 类的 drawRect。类似于“外观”类属性的东西。本质上,我需要为应用程序中的所有按钮使用我自己的绘图例程。最好我不想继承并且必须在 Storyboard 中的每个按钮上设置类类型。

最佳答案

使用类类别

@interface UIView (UIViewDR)
- (void)drawRect:(CGRect)rect;
@end


@implementation UIView (UIViewDR)
- (void)drawRect:(CGRect)rect { /* your implementation */ return; }
@end

您可能会使用 UIView 以外的类;就像按钮所基于的东西。

关于ios - 是否可以在没有继承的情况下覆盖类上的 drawRect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10661971/

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