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

标签 ios overriding drawrect

我需要知道是否可以全局覆盖 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/

相关文章:

ios - 以编程方式更改 View Controller

java - 在 scala 中使用 super

vb.net - .NET Designer 在继承的控件中将隐藏属性设置为只读

Java: "non-static method drawRect"错误

ios - UISearchBar 没有响应

ios - 数组有追加,但里面没有值

ios - 如何确定iOS中的第一周?

scala - 继承 : override in class constructor

performance - drawRect 性能

ios - -drawRect : is called within a UIView? 之后会发生什么