saintjab saintjab - 2 years ago 104
iOS Question

Draw a plus (+) sign uisng CALayer

I am not good with CALayer but I need to draw a plus (+) sign and I don't want to use an image as I want to animate the drawing. Any help?

Answer Source

After all the down votes, I was able to do it myself. Here's how for others who might need this

CGFloat height = 2.f;
CGFloat width = 3.f;
CGFloat cornerRadius =  1.f;

CALayer *hLayer = [CALayer layer];//this is the left - right stroke 
hLayer.frame = CGRectMake(0, CGRectGetMidY(self.bounds)-(height/2), width, height);
hLayer.cornerRadius = cornerRadius;

CALayer *vLayer = [CALayer layer];// this is the top - bottom stroke
vLayer.frame = CGRectMake(CGRectGetMidX(self.bounds) - (height/2), -3,height, width);
vLayer.cornerRadius = cornerRadius;

[self.layer addSublayer:hLayer];
[self.layer addSublayer:vLayer];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download