美文网首页
swift3.0 - UIView+Extension

swift3.0 - UIView+Extension

作者: 07212a79db66 | 来源:发表于2016-08-11 16:21 被阅读89次
    //
    //  UIView+Extension.swift
    //  WBDemo
    //
    //  Created by zhaodajun on 16/8/10.
    //  Copyright © 2016年 zhaodajun. All rights reserved.
    //
    
    import UIKit
    
    extension UIView {
        
        public var x: CGFloat{
            get{
                return self.frame.origin.x
            }
            set{
                var r = self.frame
                r.origin.x = newValue
                self.frame = r
            }
        }
        
        public var y: CGFloat{
            get{
                return self.frame.origin.y
            }
            set{
                var r = self.frame
                r.origin.y = newValue
                self.frame = r
            }
        }
        
        public var rightX: CGFloat{
            get{
                return self.x + self.width
            }
            set{
                var r = self.frame
                r.origin.x = newValue - frame.size.width
                self.frame = r
            }
        }
        
        public var bottomY: CGFloat{
            get{
                return self.y + self.height
            }
            set{
                var r = self.frame
                r.origin.y = newValue - frame.size.height
                self.frame = r
            }
        }
        
        public var centerX : CGFloat{
            get{
                return self.center.x
            }
            set{
                self.center = CGPoint(x: newValue, y: self.center.y)
            }
        }
        
        public var centerY : CGFloat{
            get{
                return self.center.y
            }
            set{
                self.center = CGPoint(x: self.center.x, y: newValue)
            }
        }
        
        public var width: CGFloat{
            get{
                return self.frame.size.width
            }
            set{
                var r = self.frame
                r.size.width = newValue
                self.frame = r
            }
        }
        
        public var height: CGFloat{
            get{
                return self.frame.size.height
            }
            set{
                var r = self.frame
                r.size.height = newValue
                self.frame = r
            }
        }
        
        
        public var origin: CGPoint{
            get{
                return self.frame.origin
            }
            set{
                self.x = newValue.x
                self.y = newValue.y
            }
        }
        
        public var size: CGSize{
            get{
                return self.frame.size
            }
            set{
                self.width = newValue.width
                self.height = newValue.height
            }
        }
    
    }
    
    
    

    相关文章

      网友评论

          本文标题:swift3.0 - UIView+Extension

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