Skip to content

Instantly share code, notes, and snippets.

@svyatogor
Created February 26, 2014 20:58
Show Gist options
  • Save svyatogor/9238383 to your computer and use it in GitHub Desktop.
Save svyatogor/9238383 to your computer and use it in GitHub Desktop.
class MessageCheckMark < UIView
attr_accessor :selected, :padding
def initWithFrame(frame)
if super
self.backgroundColor = UIColor.clearColor
self.padding = 8
end
self
end
def drawRect(rect)
super
unless @circle_layer
@circle_layer = CAShapeLayer.layer
@circle_layer.path = oval_path.CGPath
@circle_layer.fillColor = UIColor.clearColor.CGColor
@circle_layer.strokeColor = "#888".uicolor.CGColor
@circle_layer.lineWidth = 1
self.layer.addSublayer @circle_layer
end
end
def oval_path(padding = nil)
padding ||= @padding
UIBezierPath.bezierPathWithOvalInRect CGRectMake(padding, padding, frame.size.width - padding*2, frame.size.height - padding*2)
end
def selected=(v)
return if @selected == v || !@circle_layer
CATransaction.begin
animation = CABasicAnimation.animationWithKeyPath "path"
animation.duration = 0.25
animation.removedOnCompletion = false
animation.fromValue = @circle_layer.path
animation.toValue = oval_path(v ? 5 : padding).CGPath
@circle_layer.path = animation.toValue
@circle_layer.addAnimation animation, forKey: "animateCircle"
CATransaction.commit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment