swift 设置代理
import UIKit
// 设置代理
protocol SwiftNoDataShowViewDelegate {
func selectMoreAddAvdio() //代理方法
}
class SwiftNoDataShowView:UIView {
var delegate : SwiftNoDataShowViewDelegate? //外部实现代理
overrideinit(frame:CGRect) {
super.init(frame: frame)
self.addSubview(self.addButton);self.addSubview(self.lable)
self.backgroundColor=UIColor.white
self.isUserInteractionEnabled=true
}
//懒加载设置的button
lazy var addButton :UIButton=
{
letaddButton =UIButton()
addButton.setTitle("+ 添加音频", for: .normal)
addButton.setTitleColor(ShowOtherColorType(value:252, value1:102, value2:32), for: .normal) //自定义颜色
addButton.layer.masksToBounds=true
addButton.layer.cornerRadius=10
addButton.layer.borderColor=ShowOtherColorType(value:252, value1:102, value2:32).cgColor
addButton.layer.borderWidth=1.5
addButton.addTarget(self, action:#selector(onButtonClick), for: .touchUpInside)
return addButton
}()
@objc func onButtonClick() {
self.delegate?.selectMoreAddAvdio() //代理方法
}
overridefunclayoutSubviews() {
super.layoutSubviews()
self.addButton.frame=CGRect(x:screenWidth/2.0-80, y:KScreenNewValueWidth(Value:150), width:160, height:40)
self.lable.frame=CGRect(x:70, y:self.addButton.frame.maxY+30, width:screenWidth-140, height:60)
}
required init?(coder aDecoder:NSCoder) {
fatalError()
}
}