之前写过了替换工程里所有的UISwitch https://blog.csdn.net/qq_15509071/article/details/78639187
现在又要替换UIAlertView和UIActionSheet
UIActionSheet使用的不多,按照系统的属性方法名,重新定义一个类 实现一下就好,和UISwitch那个类似。
这里以UIAlertView为例,因为它使用的特别多,直接在工程里能搜到500多个,肯定不能一个一个改。
为什么要改它呢,因为调整了系统字体后UIAlertView的字体也会跟着变化,就像这个
目的是做成UIAlertView的字体不随系统字体变化而变化。
怎么实现呢
1.自己写个一样的,但其实这个警告框挺复杂的,写了一些,然后发现GitHub有一个几乎和系统一样的XXXAlertView所以就用它来替换。
2.使用宏定义把系统的全部替换 #define UIAlertView XXXAlertView
3.然后在第三方代码里把原来调用的方法实现一下(我是又写了一个类,不建议,这样需要多创建一个类,调用会有点乱)
eg
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
- (instancetype _Nullable )initWithTitle:(nullable NSString *)title message:(nullable NSString *)message delegate:(nullable id )delegate cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSString *)otherButtonTitles, ...;
- (void)show;
4.把delegate传递好,不要提前释放,
5.由于被showWithCompletionHandler封装过,这里需要把第三方代理方法也写上。
原理就这么多