Skip to content

Instantly share code, notes, and snippets.

@dedeexe
Last active September 28, 2016 13:23
Show Gist options
  • Save dedeexe/0d09ee8fac4a1f9e068dd5194d88d061 to your computer and use it in GitHub Desktop.
Save dedeexe/0d09ee8fac4a1f9e068dd5194d88d061 to your computer and use it in GitHub Desktop.
import UIKit
public class ResearchButton : UIButton {
private var markView : UIView!
private var circlePath : UIBezierPath!
private var circleLayer : CAShapeLayer!
public var borderWeight : CGFloat = 2
public override init(frame: CGRect) {
super.init(frame: frame)
initializeConfigurations()
updateComponent()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initializeConfigurations()
updateComponent()
}
private func initializeConfigurations() {
markView = UIView()
self.addSubview(markView)
}
func updateComponent() {
let componentFrame = self.frame
let refSize = componentFrame.width > componentFrame.height ? componentFrame.height : componentFrame.width
let offset = CGFloat(10)
let imageRect = CGRect(x: 0, y: 0, width: refSize, height: refSize)
self.imageView?.frame = imageRect
self.imageView?.contentMode = .ScaleAspectFill
self.imageView?.layer.cornerRadius = refSize / 2
self.imageView?.layer.masksToBounds = true
markView.layer.cornerRadius = refSize / 2
markView.layer.masksToBounds = true
var labelHeight : CGFloat = self.frame.height - offset - refSize
labelHeight = labelHeight > 0 ? labelHeight : 0
self.titleLabel?.frame = CGRect(x: 0,
y: refSize + offset,
width: refSize,
height: labelHeight)
self.titleLabel?.textAlignment = .Center
self.titleLabel?.numberOfLines = 3
let point = CGPoint(x: refSize / 2, y: refSize / 2)
circlePath = UIBezierPath(arcCenter: point,
radius: refSize / 2 - borderWeight,
startAngle: CGFloat(M_PI * 270 / 180),
endAngle: CGFloat(M_PI * 269 / 180),
clockwise: true)
circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
circleLayer.fillColor = UIColor(colorLiteralRed: 0.5, green: 0.5, blue: 0.5, alpha: 0.0).CGColor
circleLayer.strokeColor = UIColor.redColor().CGColor
circleLayer.lineWidth = borderWeight
self.imageView?.layer.addSublayer(circleLayer)
}
func animateMark() {
//circleLayer =
}
public override func layoutSubviews() {
super.layoutSubviews()
updateComponent()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment