添加一个新的文件,选择swift file 创建就可以
设置你要写成公共的方法,如屏幕的宽度,颜色等等
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
let StatusBarHeight = UIApplication.shared.statusBarFrame.size.height
funcShowColorType(value:CGFloat) ->UIColor{
returnUIColor.init(red: value/255.0, green: value/255.0, blue: value/255.0, alpha:1)
}
publicfuncShowOtherColorType(value:CGFloat,value1:CGFloat,value2:CGFloat) ->UIColor{
returnUIColor.init(red: value/255.0, green: value1/255.0, blue: value2/255.0, alpha:1)
}
extension UIView {
// .x
public var x: CGFloat {
get{
returnself.frame.origin.x
}
set{
varrect =self.frame
rect.origin.x= newValue
self.frame= rect
}
}
// .y
public var y: CGFloat {
get{
returnself.frame.origin.y
}
set{
varrect =self.frame
rect.origin.y= newValue
self.frame= rect
}
}
// .maxX
public var maxX: CGFloat {
get{
returnself.frame.maxX
}
}
// .maxY
public var maxY: CGFloat {
get{
returnself.frame.maxY
}
}
// .centerX
public var centerX: CGFloat {
get{
returnself.center.x
}
set{
self.center=CGPoint(x: newValue, y:self.center.y)
}
}
// .centerY
public var centerY: CGFloat {
get{
returnself.center.y
}
set{
self.center=CGPoint(x:self.center.x, y: newValue)
}
}
// .width
public var width: CGFloat {
get{
return self.frame.size.width
}
set{
varrect =self.frame
rect.size.width= newValue
self.frame= rect
}
}
// .height
public var height: CGFloat {
get{
return self.frame.size.height
}
set{
varrect =self.frame
rect.size.height= newValue
self.frame= rect
}
}
}
网友评论