core-graphics

Polygon with rounded corners using UIBezierPath

青春壹個敷衍的年華 提交于 2019-12-14 04:16:59
问题 I would like to use UIBezierPath to create a polygon shape with rounded corners. I believe this will be possible using addCurveToPoint:controlPoint1:controlPoint2: and similar code to that found in http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit, but I was wondering if there's any existing (or better) way to achieve this? I should point out that this will need to be for any convex polygon (such as found in a voronoi diagram) and not just a

How to draw an animatable ruler with Quartz2D?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:57:17
问题 I'd like to draw the lines of a simple ruler with Quartz2D, just for practice. Since I have no idea about doing vector graphics programmatically on the iPhone, maybe someone can point me to a good tutorial to get started? 回答1: As Plamen points out, the Quartz 2D documentation is worth reading. Additionally, the course notes are available online (VoodooPad format) for my iPhone development course, where I devote an entire class to Quartz 2D drawing. The QuartzExamples sample application I

Zoomable Graphics

对着背影说爱祢 提交于 2019-12-14 03:19:42
问题 I am trying to draw zoomable graphics onto the screen. I currently have a UIView inside of a ScrollView and I'm wondering what the best way is to go about handling/implementing zooming of the graphics I've drawn on the screen. 回答1: You'll probably want to use something along the lines of what I describe in my answer here. During the pinch-zooming event, a transform will be applied to your UIView, which will zoom the content but will lead to blurring. Once the zooming event is finished, use

iOS - Rotate a layer right and left using two different UIButtons

喜夏-厌秋 提交于 2019-12-14 03:19:22
问题 I created a layer using CALayer and animated it using CABasicanimation with rotate animation and created two TouchDown UIButtons to rotate it left and right, I got a problem when the layer rotates right it gets back to the original angle and the same with left rotation Here's my code: -(void)viewDidLoad { //Button 1 UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; aButton.frame = CGRectMake(0, 0, 145, 145); aButton.center = CGPointMake(90, 190); aButton.backgroundColor =

Trouble with layer.shadowColor and UIColors

拟墨画扇 提交于 2019-12-13 21:21:23
问题 Trying to change the color of a shadow. This works: self.layer.shadowColor = [[UIColor blueColor] CGColor]; but i want to make it a custom color, so i tried: self.layer.shadowColor = [[UIColor colorWithRed:191/255.0f green:199/255.0f blue:203/255.0f alpha:1] CGColor]; which does not work. what am i doing wrong? EDIT: code snippet from my init method: self.layer.shadowOpacity = 0; self.layer.shadowColor = [[UIColor blueColor] CGColor]; //self.layer.shadowColor = [[UIColor colorWithRed:191/255

Rendering PDF in iOS using drawRect and drawLayerInContext

拟墨画扇 提交于 2019-12-13 20:07:33
问题 I'm creating a custom view that renders a PDF to its bounds rectangle . I have pasted the code below : CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0); CGContextFillRect(context, self.bounds); CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); CGFloat scale = MIN(self.bounds.size.width / pageRect.size.width, self.bounds.size.height / pageRect.size.height); CGContextSaveGState(context); CGContextTranslateCTM(context, 0.0, self.bounds.size.height); CGContextScaleCTM(context, 1.0,

Converting Array of Pixel Brightness Values Back into UIImage?

拜拜、爱过 提交于 2019-12-13 20:06:10
问题 A while ago I used the following method to extract an array of pixel brightness values from 32x32 sized images. I'd like to convert these values back into the 32x32 png images if possible (The images were black and white so the red green and blue values should be equal for each pixel). Here is the original method I used: - (NSArray *)arrayOfPixelBrightnessFromImage:(UIImage *)image { NSMutableArray *pixelBrightnesses = [[NSMutableArray alloc] init]; CGImageRef inputCGImage = [image CGImage];

Scale a Bezier Curve Proportionally - calculate control points

孤街浪徒 提交于 2019-12-13 18:26:43
问题 I'm trying to take a bezier curve (any arbitrary curve in Core Graphics) and shrink (or expand) it proportionally given another two end points. I have an approach that sort of works, but it ends up 'flattening' out the curves, and not retaining the shape exactly. Maybe I've messed up the code or logic, but I have the two original points along with the control point(s). Given another set of end points I want to calculate the appropriate control points to produce the same shape between the new

Horizontal center text using objective-c / core graphics

倖福魔咒の 提交于 2019-12-13 16:42:19
问题 I'm trying to center a text on an iPhone screen using Core Graphics and I found this code. CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; NSString * text = @"text"; CGFloat minHeight = 40; float widthIs = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, minHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName:[UIFont systemFontOfSize:22.0] } context:nil].size

drawRect - Draw Star

淺唱寂寞╮ 提交于 2019-12-13 16:24:42
问题 I am drawing annotations on a view. The approach i am using to draw star is below. -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGFloat xCenter = rect.size.width / 2; CGFloat yCenter = rect.size.height / 2; float width; if(rect.size.width > rect.size.height) { width = rect.size.height; } else { width = rect.size.width; } double r = width / 2.0; float flip = -1.0; double theta = 2.0 * M_PI * (2.0 / 5.0); // 144