motion-paintcode
motion-paintcode copied to clipboard
Using variables / functions
Hey man - great little piece of code -- surprised there's not a lot of people using it though.
You know Paintcode has added functions and variables; I've got one that I'm using for a battery graphic - you know scaling the 'juice' on a battery depending on 0.0 - 1.0 being sent in.
How would I best use this in RubyMotion? Still create a Battery UIView class and drop all this in the drawRect?
`def batteryLevel(batteryLevel) ## General Declarations context = UIGraphicsGetCurrentContext()
## battery
## batteryOutline Drawing
batteryOutlinePath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(0, 0, 116, 52), cornerRadius:7)
UIColor.whiteColor.setStroke
batteryOutlinePath.lineWidth = 3
batteryOutlinePath.stroke
## cap Drawing
# capPath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(119.5, 15.5, 9, 20) byRoundingCorners: UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii: CGSizeMake(4.5, 4.5)]
# capPath.closePath
# UIColor.whiteColor.setFill
# capPath.fill
## fill Drawing
CGContextSaveGState(context)
CGContextTranslateCTM(context, 5.13, 26.5)
CGContextScaleCTM(context, batteryLevel, 1)
fillPath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(-0.09, -21.5, 105.82, 42), cornerRadius:3)
UIColor.whiteColor.setFill
fillPath.fill
CGContextRestoreGState(context)
end `
Also unsure about that byRoundCorners that's commented out.