LoginSignup
5
4

More than 5 years have passed since last update.

カスタムUIViewのサンプル

Posted at

汎用的なUIViewを自作したい時のサンプル

CustomUIViewSample.swift
import UIKit

class CustomUIView: UIView {

    var nibView: UIView!

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

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

    func setup() {
        self.nibView = NSBundle.mainBundle().loadNibNamed("???", owner: self, options: nil).first as! UIView
        self.nibView.frame = self.bounds
        self.nibView.translatesAutoresizingMaskIntoConstraints = true
        self.nibView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        self.addSubview(self.nibView)
    }
}
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4