core-graphics

How to create a multiline string or multiline label as a CGPath in iOS?

烂漫一生 提交于 2019-12-11 02:24:55
问题 Does the API support this? If not, how could I do it? There is CTFontCreatePathForGlyph in Core Text, which can translate a single character into a path. I could use that in a loop to create my string as a path, but I'd have to deal with spacing and kerning and all the other nasty things. I'm looking for a string path that would looks the same if it was drawn in a UILabel with same font and size. 回答1: There is an article called Low-level text rendering by Ohmu that covers this pretty

Recreate Apple Watch fitness tracker ‘progress’ bar - gradient on CAShapeLayer stroke

老子叫甜甜 提交于 2019-12-11 02:16:59
问题 I'm writing an app that could make good use of the Apple Watch's fitness tracker design, here: So far, I've created the basic outline which is just a CAShapeLayer with a CGPath of an ellipse. I use strokeStart and strokeEnd to animate the progress. My problem comes when applying a gradient to the outline. How do I apply a gradient like above to the stroke of a CGPath? 回答1: The cleanest way to do this without having to drop down to Core Graphics or GL is to create a layer containing the angle

Draw transparent UIBezierPath line inside drawRect

霸气de小男生 提交于 2019-12-11 01:08:37
问题 I am trying to achieve a transparency path in the drawRect method. This is the simple code I have created: override func drawRect(rect: CGRect) { let clippingPath = UIBezierPath() UIColor.whiteColor().set(); clippingPath.moveToPoint(CGPoint(x: 10, y: CGRectGetHeight(self.bounds) / 2)) clippingPath.addLineToPoint(CGPoint(x: CGRectGetWidth(self.bounds) - 10, y: CGRectGetHeight(self.bounds) / 2)) clippingPath.lineWidth = 6 clippingPath.lineCapStyle = .Round clippingPath.stroke() } And this is

Why does combining PDF pages with CGContextDrawPDFPage create very large output files?

一世执手 提交于 2019-12-11 01:05:48
问题 I ran into this trying to throw together a simple Automator script to combine several one-page PDF files. I had 88 files to combine, each just about exactly 300KB, so I expected the final product to be about 30MB; the resulting PDF file, using the Combine PDFs Automator action, was 300+MB. Poking around, the Automator action uses a Python script, with Foundation bindings, to create the new PDF document with the CoreGraphics PDF APIs. Nothing seems out of place. Basically, it's doing this

Zoom Core Graphics in UIScrollView

时间秒杀一切 提交于 2019-12-11 00:47:17
问题 I was wondering which would be the best way to scale my Core Graphics drawings as I zoomed in using a UIView subclass within a UIScrollView. Currently when I zoom in, the drawing becomes slightly fuzzy - I know this is correct functioning, I just want to know how developers override it to keep the image sharp... Thanks! (P.s. I have heard about using Core Animation, but I don't know where to start on that huge library with scary names haha!) 回答1: The simplest way is to use supersampling.

Bubble chart , scatter chart ,candlestick chart using core plot

放肆的年华 提交于 2019-12-11 00:46:36
问题 One my ipad project needs to have 8 kinds graph and chart which include 3 variables bubble chart,scatter chart , candlestick chart etc.A quick search gave me result as a core plot which is currently the most used solution for graph and chart in ios.But when i went in there page i didn't see any kind bubble chart or scatter chart implementation. My Question is.. Is it possible to draw 3 variable bubble chart,scatter chart or candlestick chart in coreplot ??or i need to draw the whole graph

Programmatically disable shake to find

冷暖自知 提交于 2019-12-10 22:28:06
问题 Mac os El Capitan introduced a feature called "Shake mouse pointer to locate" - it seems to ignore the cursor visibility set by CGDisplayHideCursor / CGDisplayShowCursor I need to completely hide the mouse cursor for my cross platform first person game. How can I get around this problem? 回答1: No system event to handle this in my experience. It's not the prettiest, but you can follow the advice in this blogpost and rehide the cursors when listening to the mouseMove event. override func

Creating pattern on-the-fly?

﹥>﹥吖頭↗ 提交于 2019-12-10 21:27:47
问题 Is there a way to create a colored fill pattern dynamically in Cocoa? In particular instead of using a fixed pattern from an image file via NSColor *fillPattern = [NSColor colorWithPatternImage:patternImage]; I'd like to create a pattern by dynamically choosing the appropriate colors at runtime. Background is highlighting a colored object by rendering stripes or squares in the ''opposite'' color on top of it - whatever opposite might mean in this context, but that's a different story.. Being

Alternative for sizeWithFont: method

为君一笑 提交于 2019-12-10 21:22:23
问题 I have a class which work is to parse a text into several pages. I use sizeWithFont: method to identify when one page ends and another starts. But unfortunately since the amount of text which needs to be parsed is pretty big, whole operation needs to be performed on a background thread (takes several second to complete). And therefore sometimes I get visual artifacts on my interface (UIKit is not thread safe but I call it from several threads simultaneously), which I would love to get rid of.

drawRect: speed and CGContextDrawRadialGradient (super slow?)

北城以北 提交于 2019-12-10 21:14:32
问题 I'm having problems with my UIView subclass' drawRect: function. I use CGContextDrawRadialGradient() in it, and it. When the user drags my UIView it struggled to keep up if I include the gradient. Using Time Profiler I see that literally > 98% of my time is spent in my subclass' drawRect : method. First: would using a static image of a gradient be faster? Second: is there any way to speed this up? Can I cache the gradient somehow? it doesn't change much but paths around it and intersecting it