extension UIButton {
private struct mhf_associatedKeys{
static var mhf_paramDic = "mhf_paramDic"
}
var mhf_paramDic: Dictionary<String, String> {
get{
if let par = objc_getAssociatedObject(self, &mhf_associatedKeys.mhf_paramDic) as? Dictionary<String, String> {
return par
}
return [:]
}
set(newPar){
objc_setAssociatedObject(self, &mhf_associatedKeys.mhf_paramDic, newPar, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
直接调用 btn.mhf_paramDic = [“linkUrl”:linkUrl]