• iOS(Swift)学习笔记之SnapKit+自定义UI组件


    本文为原创文章,转载请标明出处

    1. 通过CocoaPods安装SnapKit

    platform :ios, '10.0'
    
    target '<Your Target Name>' do
    
      use_frameworks!
    
      pod 'SnapKit', '~> 4.0.0'
    
    end
    

    2. 自定义UI组件

    import UIKit
    import SnapKit
    
    class CustomView: UIView {
    
        var isFirstLayout: Bool = true
    
        lazy var firstView: UIView = {
            let firstView: UIView = UIView()
            return firstView
        }()
    
        lazy var secondView: UIView = {
            let secondView: UIView = UIView()
            return secondView
        }()
    
        override init(frame: CGRect) {
            super.init(frame: frame)
            self.commonInit()
        }
    
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            self.commonInit()
        }
    
        func commonInit() {
            self.addSubview(self.firstView)
            self.addSubview(self.secondView)
        }
    
        override func layoutSubviews() {
            super.layoutSubviews()
    
            if self.isFirstLayout {
                self.firstView.snp.makeConstraints { (make) -> Void in
    
                }
    
                self.secondView.snp.makeConstraints { (make) -> Void in
    
                }
    
                self.isFirstLayout = false
            }
        }
    }
    
    
  • 相关阅读:
    Excel sheet Column Title
    Add Two Numbers
    Add Binary
    Excel Sheet Column Number
    Lowest Common Ancestor of a Binary Search Tree
    Invert Binary Tree
    Move Zeroes
    Contains Duplicate
    Maximum Depth of Binary Tree
    Java实现二叉树的构建与遍历
  • 原文地址:https://www.cnblogs.com/metaphors/p/9405371.html
Copyright © 2020-2023  润新知