简体   繁体   中英

How to divide UIView N number of equal UIView

I'm new to iOS, I want to divide the UIView frame in to N equals size UIView frame based on the center point of the UIView .

For Example i done for the circle: http://s14.postimg.org/6w4xfa80h/i_OS_Simulator_Screen_shot_Mar_31_2014_7_03_03_P.png

Same way i have to do. but the shape of the view corner is not the arc, it should be same as view rectangle frame.

How can i achieve.

If I understand correctly, what you're trying to do is creating views that look like the following:

8路分割

Note that the areas are not rectangular, so they cannot be view frames. They are shapes that can be created via CGPath functions. An easy way to create those lines is with CGPathAddLineToPoint . Always add a line that starts at the center of the view and goes down far the y coordinate. All you have to do is change the CGAffineTransform *m parameter by calling repeatedly CGAffineTransformRotate with an angle = 2*pi/n where n is the number of equal parts.

Assuming you have a CGAffineTransform t and the aforementioned angle, you'd loop n times:

CGPathRef path = CGPathCreateMutable(); CGPathAddLineToPoint(path, CGAffineTransformRotate(t,angle), view.frame.center.x, view.frame.center.y + view.frame.size.y); // Now do something with that line....

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