我想扩展基类(UIView),我在其中处理该对象并返回具有正确类型的调用对象
extension UIView {
func withCleanBg() -> UIView {
self.backgroundColor = .clear
return self;
}
}
例如,如果我调用 let btn:UIButton = UIButton().withCleanBg()
我希望 btn
在调用扩展后保持 UIButton 而不是 UpCasted .
我希望它能够链接函数调用,例如
UIButton().withCleanBg().withFillInParent()
等等
最佳答案
返回 Self
作为类型:
func withCleanBg() -> Self {
关于ios - Swift 扩展 UIView 返回调用类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67695542/