Created
April 12, 2018 09:19
-
-
Save godrm/a8f6a9ea8e5f9a0559c7c70c40311f96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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