Skip to content

Instantly share code, notes, and snippets.

@godrm
Created April 12, 2018 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godrm/a8f6a9ea8e5f9a0559c7c70c40311f96 to your computer and use it in GitHub Desktop.
Save godrm/a8f6a9ea8e5f9a0559c7c70c40311f96 to your computer and use it in GitHub Desktop.
//
// MyCustomView.swift
// CustomView
//
// Created by JK on 12/04/2018.
// Copyright © 2018 JK. All rights reserved.
//
import UIKit
class MyCustomView: UIView {
override init(frame: CGRect) { // by code
super.init(frame: frame)
configuration()
}
//---------------------------
override func awakeFromNib() {
super.awakeFromNib()
//
}
required init?(coder aDecoder: NSCoder) { // by Unarchiver -
super.init(coder: aDecoder)
//
configuration()
}
private func configuration() {
self.layer.cornerRadius = 100
self.layer.masksToBounds = true
let layer = CALayer.init()
layer.backgroundColor = UIColor.yellow.cgColor
layer.frame = self.frame.insetBy(dx: 30, dy: 30)
layer.cornerRadius = 100
layer.masksToBounds = true
layer.borderWidth = 10
layer.borderColor = UIColor.purple.cgColor
self.layer.addSublayer(layer)
self.layer.borderWidth = 10
self.layer.borderColor = UIColor.purple.cgColor
}
override func draw(_ rect: CGRect) {
super.draw(rect)
// Drawing code
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(UIColor.red.cgColor)
context?.fill(rect)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment