core-graphics

Cocoa Touch - Adding texture with overlay view

可紊 提交于 2019-12-20 03:03:34
问题 I have a set of tiles as UIViews that have a programmable background color, and each one can be a different color. I want to add texture, like a side-lit bevel, to each one. Can this be done with an overlay view or by some other method? I'm looking for suggestions that don't require a custom image file for each case. 回答1: This may help someone, although this was pieced together from other topics on SO. To create a beveled tile image with an arbitrary color for normal and for retina display, I

Create a circle with multi coloured segments in Core Graphics

♀尐吖头ヾ 提交于 2019-12-19 11:56:48
问题 I am trying to draw a pie chart which will be made up of equal sized segments, each with a different colour. I am basing my code off this SO: Draw a circular segment progress in SWIFT let circlePath = UIBezierPath(ovalInRect: CGRect(x: 200, y: 200, width: 150, height: 150)) var segments: [CAShapeLayer] = [] let segmentAngle: CGFloat = 1.0 / CGFloat(totalSegments) for var i = 0; i < totalSegments; i++ { let circleLayer = CAShapeLayer() circleLayer.path = circlePath.CGPath // start angle is

Draw VU meter using Core Graphics in iOS

好久不见. 提交于 2019-12-19 10:17:06
问题 I'm trying to draw a somewhat similar image to this, using Core Graphics: I was able to draw the main arc, but I am not able to understand, how to divide arc into parts/draw graduation on arc? My current code to draw the arc is: [path addArcWithCenter:point radius:radius startAngle:DEGREES_TO_RADIANS(specific_start_angle) endAngle:DEGREES_TO_RADIANS(specific_end_angle) clockwise:NO]; I tried using strokeWithBlendMode but I am facing problem with position of graduations or ticks. 回答1: Teja's

UIGraphicsGetCurrentContext() short lifetime

限于喜欢 提交于 2019-12-19 10:11:41
问题 I have a view which implements freehand drawing, but I have a small problem. I noticed on the iPad 3 that everything went to hell, so I tried to update my drawing code (probably as I should have done in the first place) to only update the portion that was stroked. However, the first stroke after open, and the first stroke after about 10 seconds of idle are extremely slow. After everything is "warmed up" it is smooth as butter and only takes about 0.15ms per drawRect. I don't know why, but the

Flip UIImage Along Either Axis

☆樱花仙子☆ 提交于 2019-12-19 09:00:10
问题 I'm trying to create a method which flips a UIImage along the X axis, Y axis, or both. I keep getting close but my transform knowledge isn't good enough to get all the way there. Here is the code I have so far: - (UIImage *)flippedImageByAxis:(MVImageFlip)axis{ UIGraphicsBeginImageContext(self.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGAffineTransform verticalFlip = CGAffineTransformMake(1, 0, 0, -1, 0, self.size.height); CGAffineTransform horizFlip = CGAffineTransformMake

Embed hyperlink in PDF using Core Graphics on iOS

你说的曾经没有我的故事 提交于 2019-12-19 08:06:15
问题 I'm trying to do a quite simple thing: write an URL inside a PDF file that can be actually clicked by the user. I know for sure that using libharu it can be done. What I'm looking for is to do the same using Core Graphics since the whole code I already have in my app is already using those methods. == edit == I think I found something: UIGraphicsSetPDFContextURLForRect but I can't make it to work. I'm using something like: NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

Get position of path at time

心已入冬 提交于 2019-12-19 08:00:53
问题 is there a nice way to calculate the position of a path (CGPath or UIBezierPath) at a given time (from 0 to 1)? Using CAShapeLayer for example, one can create an animated stroke end. I want to know the position of that stroke end at arbitrary times. Thanks in advance, Adrian 回答1: You can definitely base your approach on the CADisplayLink and a tracking layer. However, if you don't mind doing a little bit of math on your own, the solution is not too complicated. Plus, you wont have to depend

CALayer compositingFilter, iOS 5 and CoreImage

半城伤御伤魂 提交于 2019-12-19 07:35:33
问题 The API Docs for CALayer state: (I'm not sure if the docs are up to date??) compositingFilter A CoreImage filter used to composite the receiver’s contents with the background. Animatable. @property(retain) id compositingFilter ... Special Considerations While the CALayer class exposes this property, Core Image is not available in iOS. Currently the filters available for this property are undefined. But CoreImage IS available on iOS5, so could I add a CoreImage filter to a CALayer and add that

Can someone explain the CALayer contentsRect property's coordinate system to me?

空扰寡人 提交于 2019-12-19 03:11:49
问题 I realize that the contentsRect property of CALayer (documentation here) allows one to define how much of the layer to use for drawing, but I do not understand how the coordinate system works, I think. It seems that when the width/height are smaller, the area used for content is bigger and vice versa. Similarly, negative x,y positions seem to move the content area down and to the right which is the opposite of my intuition. Can someone explain why this is? I'm sure there is a good reason, but

Can someone explain the CALayer contentsRect property's coordinate system to me?

爷,独闯天下 提交于 2019-12-19 03:10:03
问题 I realize that the contentsRect property of CALayer (documentation here) allows one to define how much of the layer to use for drawing, but I do not understand how the coordinate system works, I think. It seems that when the width/height are smaller, the area used for content is bigger and vice versa. Similarly, negative x,y positions seem to move the content area down and to the right which is the opposite of my intuition. Can someone explain why this is? I'm sure there is a good reason, but