Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS UIView layer setCornerRadius in ellipse shape

I have a little doubt to make a ellipse shape using UIView.

My view has a dimension like w:50.0f e h:20.0f and using this command:

[[viewElement layer] setCornerRadius:w/2];

But the shape isn't a good shape for ellipse.

I want this:

shape

The borders of shape is distorted, can I make an ellipse shaped like which is expected?

Thanks

like image 676
sidneivl Avatar asked Nov 18 '25 20:11

sidneivl


1 Answers

Try this:

viewElement.frame = CGRectMake(0, 0, w, w);
viewElement.layer.cornerRadius = w / 2;
viewElement.transform = CGAffineTransformMakeScale(1, h / w);
like image 123
Amon Avatar answered Nov 20 '25 09:11

Amon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!