Analog clock with UIImages for hands?

前端 未结 2 610
余生分开走
余生分开走 2021-01-03 07:57

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:

2条回答
  •  旧时难觅i
    2021-01-03 08:46

    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.

提交回复
热议问题