Bezier curves are very handy to point to objects in your interface, for onboarding and help screens:
Create and edit arrows to light up your interface, with visual preview in Xcode Storyboard and Interface Builder.
In Interface Builder, position a BezierCurveView
and drop two BezierCurveHandle
inside it.
BezierCurveView
represents the drawing space. It can be as large as theUIWindow
to prevent curve clipping.BezierCurveHandle
represents the two handles required by a Cubic Bezier Curve. It adopts theBezierHandleProtocol
, which provides control point information.
The combination BezierCurveView
+ 2 BezierCurveHandle
yields live preview in Interface Builder, with unprecedented flexibility:
.
Because a BezierCurveHandle
is itself a UIView
, it can be controlled by AutoLayout constraints, and thus adapt automatically to changes in sizes and orientations, with exactly 0 lines of code. And since these handles are themselves extensions to the BezierHandleProtocol
, you can tailor any of your UIView
subclasses to control handles as well.
- Make sure that a
BezierCurveView
contains exactly two subviews adoptingBezierHandleProtocol
for any drawing to take place - In most situations,
BezierCurveView
andBezierCurveHandle
background color should be clear BezierCurveView
will be refreshed any time itsframe
is updated, providing dynamic animations: (replay)
IBInspectable | What it does |
---|---|
lineWidth |
bezier curve thickness ; default is 1.5 |
tintColor |
color of the curve ; defaults to black if absent |
IBInspectable | What it does |
---|---|
dx |
horizontal component of the control point ; default is 0 |
dy |
vertical component of the control point ; default is -10.0 (control point is 10.0 pixels below the anchor |
shape |
one of none , arrowHead , circle or disc , default is none |
size |
dimensions of the shape : a shaft length for the arrow, a radius for circles and discs (†) ; default is 15.0 |
(†) The bezier curve end point is adjusted to start from the end of the shape
Use Cocoapods or include the source file directly. Cocoapods preferred.
API Compatibility: version 4.x introduces BezierHandleProtocol
, BezierHandleView
and BezierCurveView
, deprecating 3.x BezierCurveArrowView
.
Run pod install
in the BezierCurveExample
directory, open BezierCurveExample.xcworkspace
and run.
Search for BezierCurveView answers on Stack Overflow, or ask questions to be adressed by the community. You can also contact the author.