简体   繁体   中英

How to create concave shape of a UIView

Is it possible to make a concave shape of the side of a view?

I managed to round the edges with border radius, but I wonder if it's possible to make other nice transformations. Here is the example:

1)This is my progress so far: 在此处输入图片说明

2)This is how it should be: 在此处输入图片说明

Is it possible to make a view look this way programmatically? If not, I guess I'll use a png image to achieve this, but it's always nicer to finish these sort of stuff through code

You can use UIBezierPath / CGPath to achieve this.

There is a good documentation from Apple about drawing, giving you hints ont curves, lines, etc:

Once you created your shape:

CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:[viewToMask bounds]];
[maskLayer setPath:[theBezierPath CGPath]];
[viewToMask layer] setMask = layer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM