Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analog clock with UIImages for hands?

I want to know how to make an analog clock in iPhone SDK. However, I want the hands of the clock to be custom images and not squares drawn over like in this tutorial: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html

The problem with that tutorial is that the clock hands are drawn with Quarzt Core. I'm okay with that as long as the hands could be custom. What would be the easiest way to make an Analog Clock this way?

like image 697
Andy B Avatar asked Dec 16 '22 18:12

Andy B


1 Answers

Do it with CALayers. is WAY much easier and performance is better this way.

CALayer *handLayer = [CALayer layer];
handLayer.contents = (id)[UIImage imageNamed:@"hand.png"].CGImage;
handLayer.anchorPoint = CGPointMake(0.5,0.0)];
[myview.layer addSublayer:handLayer];

//i.e.: if handLayer represents the seconds hand then repeat this every second ;)
handLayer.transform = CGAffineTransformMakeRotation (angle); //set the angle here


UPDATE:

I wrote a ClockView sample using CALayers, maybe you find it useful.

like image 80
nacho4d Avatar answered Jan 05 '23 05:01

nacho4d