ios - Circular Progress Bar help, Swift Programming Language -
ios - Circular Progress Bar help, Swift Programming Language -
i'm trying create little circular progress bar in swift,
this have far
private var timer:cgfloat = 100; override func update(currenttime: cftimeinterval) { /* called before each frame rendered */ var startangle:cgfloat! var endangle:cgfloat! var circletimer:uibezierpath! startangle = cgfloat(m_pi * 1.5) endangle = startangle + cgfloat((m_pi * 2)) var progress:cgfloat = (endangle - startangle) * (timer / 100) + startangle circletimer.addarcwithcenter(cgpointmake(200, 200), radius: cgfloat(130), startangle: startangle, endangle: progress, clockwise: true) timer--; }
i error when run app
"bad_instruction (code=exc_i386_invop, subcode=0x0)"
on line
"circletimer.addarcwithcenter(cgpointmake(200, 200), radius: cgfloat(130), startangle: startangle, endangle: progress, clockwise: true)"
i'm new swift (programmed in other languages) , can't seem work out.
thanks luke
you have not initialized circletimer
circletimer
nil.you should initialize first call
circletimer.addarcwithcenter(cgpointmake(200, 200), radius: cgfloat(130), startangle: startangle, endangle: progress, clockwise: true)
intialize path
var circletimer:uibezierpath! = uibezierpath()
also write in draw rect
override func drawrect(rect: cgrect) { /* called before each frame rendered */ var startangle:cgfloat! var endangle:cgfloat! var circletimer:uibezierpath! = uibezierpath() startangle = cgfloat(m_pi * 1.5) endangle = startangle + cgfloat((m_pi * 2)) var progress:cgfloat = (endangle - startangle) * (timer / 100) + startangle //test working fine //circletimer.addarcwithcenter(cgpointmake(50, 50), radius: cgfloat(130), startangle: 0.0, endangle: progress, clockwise: true) circletimer.addarcwithcenter(cgpointmake(200, 200), radius: cgfloat(130), startangle: startangle, endangle: progress, clockwise: true) timer--; circletimer.linewidth = 20; uicolor.redcolor().setstroke() circletimer.stroke() }
ios iphone xcode swift xcode6
Comments
Post a Comment