美文网首页SwiftSwfit学习
swift 设置oc一样效果的pch文件

swift 设置oc一样效果的pch文件

作者: 江河_ios | 来源:发表于2019-01-03 18:02 被阅读0次

    添加一个新的文件,选择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

        }

    }

    }

    相关文章

      网友评论

        本文标题:swift 设置oc一样效果的pch文件

        本文链接:https://www.haomeiwen.com/subject/bzdqrqtx.html