I have a CALayer which i a circle image, I am trying to add an external border to this. (shadows will not work for me here). I have tried resizing the CALAyer and adding the border but the positioning appears incorrect, i do not want the shape to move, just a border to be added.
here is my code
CGFloat borderWidth = 10.0f;
CGFloat xPos = cont.layer.frame.origin.x;
CGFloat yPos = cont.layer.frame.origin.y;
CGFloat contWidth = cont.layer.frame.size.width;
CGFloat contHeight = cont.layer.frame.size.width;
cont.layer.frame = CGRectMake(xPos, yPos, contWidth + borderWidth, contHeight + borderWidth);
cont.layer.cornerRadius = contWidth / 2;
cont.layer.borderColor = [[UIColor darkGrayColor] CGColor];
cont.layer.borderWidth = borderWidth;
Thanks in advance
Your code is correct.
Please add one line:
cont.clipsToBounds=YES
self.imgView1.layer.cornerRadius =self.imgView1.frame.size.width / 2;
self.imgView1.layer.borderColor = [[UIColor blueColor] CGColor];
self.imgView1.layer.borderWidth = 0.0f;
self.imgView1.layer.masksToBounds=TRUE;
After this follow the steps:
Create another UIImageView and Place it above the first imageView.
Then increase height and width of secondImageView to 20.
set secondImageView center and FirstImageCenter equal(at same point).
and Write the Following code:
self.imgView2.layer.cornerRadius=self.imgView2.frame.size.width / 2;
self.imgView2.layer.borderColor = [[UIColor blueColor] CGColor];
self.imgView2.layer.borderWidth = 10.0f;
self.imgView2.layer.masksToBounds=TRUE;
Please do above steps it will solve your problem.
Now you will get output like this: