change color and width of some painted lines in an UIImageView
I'm painting some black lines in an UIImageView
(in touchesBegan
and touchesMoved
methods) and there is one UISlider
for modifying the width of these开发者_高级运维 lines and some buttons for modifying the color of them.
How can that be done using CoreGraphics?
...
UIGraphicsBeginImageContext(theImage.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, theNewWidth);
...
Thanks
First, you shouldn't be trying to draw on a UIImageView
. Instead, create your own subclass of UIView
and override -drawRect:
. When the events for those UI controls are fired, just call -setNeedsDisplay
on your view class to ask it to be redrawn. Also, set some properties on your view class (e.g., lineWidth
, lineColor
).
In -drawRect:
, use Core Graphics to redraw your view with the new values the user specified.
You can look at the Quartz 2D Programming Guide for all the information you need about drawing with Core Graphics. Also, check out the QuartzDemo sample project from Apple. It demonstrates many, if not all, of Core Graphics's capabilities.
精彩评论