|
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() |
|
} |
|
|
|
} |