扩展

作者: 鱼得琴 | 来源:发表于2017-02-10 14:05 被阅读0次
    import UIKit
    

    UIView:

    extension UIView {
    
    var x : CGFloat {
        
        get {
            return frame.origin.x
        }
        
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.origin.x     = newVal
            frame                 = tmpFrame
        }
    }
    
    var y : CGFloat {
        
        get {
            return frame.origin.y
        }
        
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.origin.y     = newVal
            frame                 = tmpFrame
        }
    }
    
    var height : CGFloat {
        
        get {
            return frame.size.height
        }
        
        set(newVal) { 
            var tmpFrame : CGRect = frame
            tmpFrame.size.height  = newVal
            frame                 = tmpFrame
        }
    }
    
    var width : CGFloat {
        
        get {
            return frame.size.width
        }
        
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.size.width   = newVal
            frame                 = tmpFrame
        }
    }
    
    var left : CGFloat {
        
        get {
            return x
        }
        
        set(newVal) {
            
            x = newVal
        }
    }
    
    var right : CGFloat {
    
        get {
            return x + width
        }
        
        set(newVal) {     
            x = newVal - width
        }
    }
    
    var top : CGFloat {
        
        get {
            return y
        }
        
        set(newVal) {
            y = newVal
        }
    }
    
    var bottom : CGFloat {
    
        get {   
            return y + height
        }
        
        set(newVal) {
            y = newVal - height
        }
    }
    
    var centerX : CGFloat {
        
        get {
            return center.x
        }
        
        set(newVal) {
            center = CGPoint(x: newVal, y: center.y)
        }
    }
    
    var centerY : CGFloat {
        
        get {
            return center.y
        }
        
        set(newVal) {
            center = CGPoint(x: center.x, y: newVal)
        }
    }
    
    var middleX : CGFloat {
        
        get {
            return width / 2
        }
    }
    
    var middleY : CGFloat {
        
        get {
            return height / 2
        }
    }
    
    var middlePoint : CGPoint {
        
        get {
            return CGPoint(x: middleX, y: middleY)
        }
    }
    
    }

    相关文章

      网友评论

          本文标题:扩展

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