iOS development-Edge drawing controls and dashed line drawing principles

Source: Internet
Author: User

In the recent project design, there was a dashed line divider, reminiscent of a control yrborderview that was used to draw various edge effects, but only the actual lines were supported and immediately upgraded.

Supports four edges with different colors, different weights, different radians, supports clipping off edges outside, and supports dashed lines.
:

You need to try the stamp of this control: Yrborderview

For simple lines and drawing please see my previous Coregraphics Series blog:
http://blog.csdn.net/u010124617/article/details/9222753

Here again to illustrate the next dashed line drawing, using Cgcontextsetlinedash, for the equal width of the dashed line, generally:
CGFloat lengths[] = {间隔长度};
CGContextSetLineDash(context, 0, lengths,1);

You can do it.

If you need more complex drawing, you need to parse the parameters of this method:
CGContextSetLineDash(CGContextRef c, CGFloat phase,
const CGFloat lengths[], size_t count)

which

    • The first parameter is the context in which the drawing is used
    • The phase parameter indicates how much distance is skipped when drawing the first segment
    • The lengths parameter is an array of interval distances drawn
    • Count is the length of the third parameter lengths array

The more difficult to understand is lengths this parameter, in fact it is this:

Think of your dashed line, each piece of solid lines and each segment is a small line, but one part of the visible, part is not visible, then for each small line of the drawing rule is to follow the values in the lengths array to continue.
For example, lengths[] = {5,10,15};
The first paragraph length is 5---(line)
The second paragraph length is 10---(blank)
The third paragraph length is 15---(line)
Fourth paragraph length is 5---(blank)
The fifth paragraph length is 10---(line)
......

This makes up an irregular dashed line, such as

If our second parameter is set at 3, then the length of the first small segment will be 5-3=2, and then continue to be 10, 15 ... or something like that.

Hope to help everyone.

iOS development-Edge drawing controls and dashed line drawing principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.