佚名通过本文主要向大家介绍了关于感情的问题,感情问题,感情问题在线解答,如何处理感情问题,怎么处理感情问题等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:关于感情问题 关于swift30的类目问题
描述:
解决方案1:
描述:
在swift中,我在使用类目调用的时候出现了一个错误,求解答:
Use of instance member 'creatImageWithColor' on type 'UIImage'; did you mean to use a value of type 'UIImage' instead?
代码是 我直接创建了file.swift
在里面加了类目
extension UIImage {
// 颜色直接换换成图片
open func creatImageWithColor(_ color: UIColor, _ size: CGSize) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
// create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
color.setFill()
UIRectFill(rect)
let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
}
然后在VC中调用
let editBtn = UIButton.init(type: .custom)
editBtn.frame = CGRect(x:10, y:8, width:SCREEN_WIDTH - 20, height:44)
editBtn.layer.cornerRadius = 8
editBtn.layer.masksToBounds = true
editBtn.setTitle("编辑资料", for: .normal)
editBtn.setTitleColor(UIColor.white, for: .normal)
editBtn.setBackgroundImage(UIImage.creatImageWithColor(UIColor.black, CGSize(width:10, height:10)), for: .normal)
// 这里出现了 开始发的那个警告 求怎么解决
editBtn.addTarget(self, action: #selector(editNow), for: .touchUpInside)
解决方案1:
你的类函数/方法前要加关键词 static,才能直接用类名调用。