2018-01-11DM项目知识难点摘记

2018-01-11  本文已影响21人  小白猿

UI

// frame 初始化执行
  override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
// xib初始化执行
 required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
@IBDesignable
open class VCShadowView: UIView {

    @IBInspectable public var cornerRadius: CGFloat = 6.0 {
        didSet {
            _contentView.layer.cornerRadius = cornerRadius
            self.layer.cornerRadius = cornerRadius
        }
    }
    @IBInspectable public var shadowColor: UIColor = .gray {
        didSet {
            self.layer.shadowColor = shadowColor.cgColor
        }
    }

    @IBInspectable public var shadowRadius: CGFloat = 5.0 {
        didSet {
            self.layer.shadowRadius = shadowRadius
        }
    }

    @IBInspectable public var shadowOpacity: Float = 0.09 {
        didSet {
            self.layer.shadowOpacity = shadowOpacity
        }
    }

    @IBInspectable public var shadowOffset: CGSize = CGSize(width: 0, height: 2.0) {
        didSet {
            self.layer.shadowOffset = shadowOffset
        }
    }

    let _contentView = UIView()

    var contentView: UIView {
        return _contentView
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        initialize()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initialize()
    }

    fileprivate func initialize() {
        backgroundColor = .clear
        addSubview(_contentView)
        _contentView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        _contentView.backgroundColor = .white
        _contentView.clipsToBounds = true
        _contentView.layer.cornerRadius = cornerRadius
    }

    override open func draw(_ rect: CGRect) {
        super.draw(rect)
        self.layer.shadowColor = shadowColor.cgColor
        self.layer.shadowOffset = shadowOffset
        self.layer.shadowRadius = shadowRadius
        self.layer.shadowOpacity = shadowOpacity
        self.layer.cornerRadius = cornerRadius
    }
}

 imageView.contentMode = UIViewContentModeScaleAspectFill;
 imageView.clipsToBounds = YES;

Xcode

文件结构
文件夹.png

语法类

框架类

Alamofire

 /// Returns a URL that conforms to RFC 2396 or throws an `Error`.
    ///
    /// - throws: An `Error` if the type cannot be converted to a `URL`.
    ///
    /// - returns: A URL or throws an `Error`.

规范类

1.swift 枚举

上一篇 下一篇

猜你喜欢

热点阅读