core-graphics

Drawing Circular Gradient

≡放荡痞女 提交于 2019-12-03 08:28:29
I would like to draw a circular gradient like in the example picture below. I can manage a radial gradient easily but I am not sure how to do a circular one. I was thinking of drawing a gradient on a line and then transforming it to a circle. Would that be possible? This is how I draw the radial gradient: CGFloat a = MIN(self.frame.size.width, self.frame.size.height) - _lineWidth; //Get current context CGContextRef mainContext = UIGraphicsGetCurrentContext(); CGRect newRect = rect; newRect.origin.x = ((self.frame.size.width - a)/2.0f); newRect.origin.y = ((self.frame.size.height - a)/2.0f);

In iOS Development, using Core Graphics and/or Quartz 2D, how can I draw a circle filled with a gradient in such a manner that it looks like a sphere?

徘徊边缘 提交于 2019-12-03 07:55:14
So far I have looked at using CGContextDrawLinearGradient() and CGContextDrawRadialGradient(), however, with the former I can't figure out how to make the gradient look like a sphere, and with the latter, I can't figure out how to make the gradient into the shape of a sphere, because every time I try, it turns out in the shape of the full cylinder instead of only a sphere. The code I am using to current draw a 2D circle is shown below. I would like to use a gradient or any other method possible using only Core Graphics and/or Quartz 2D to fill the circle in a manner that makes it look like a

How to draw an oval speech bubble programmatically on iPhone?

久未见 提交于 2019-12-03 07:52:43
问题 The technique shown in a similar question is a rectangular bubble. How to draw one in an oval shape? i.e.:     回答1: I would do it in two iterations. First get the context and begin a path. Fill an ellipse and then a custom path that encloses a triangle with three lines. I assumed the following dimensions: 70 width, 62 height. Override draw rect in a subclass of UIView and instantiate in a subclassed UIViewController: -(void)drawRect:(CGRect)rect { CGContextRef ctx =

Core Text - Height of glyph

吃可爱长大的小学妹 提交于 2019-12-03 07:43:51
问题 I have 2 attributed strings say 'A' and '.' I need to calculate the height of each of these strings. Currently the height returned is the same for both, it seems to return the maximum possible height for the tallest character in a given font (even if that character isn't present in the string). I would like to get the exact pixel height for each of these characters, so that I can resize a view around them that fits the character (glyph) snugly. I've tried using

Applying Gradient to UIImage Smoothly

回眸只為那壹抹淺笑 提交于 2019-12-03 07:42:58
I am trying to apply gradient to UIImage using CoreGraphic; however, the result I got is not very nice. I want to create a black to transparent gradient at the bottom of the image to create a contrast for me to place some text. However, the gradient I was able doesn't blend well with the image; you can clearly see the separation in the center . The result I am looking for is like this application: http://capptivate.co/2014/02/17/yummly-3/ How should I apply the gradient to achieve this? ( I have to apply this to large quantity of images ). My Result: Here is my code: func imageWithGradient(img

UIGraphicsBeginImageContextWithOptions and Multithreading

耗尽温柔 提交于 2019-12-03 07:36:37
问题 I'm a bit confused about UIGraphicsBeginImageContextWithOptions and threading because according to UIKit Function Reference UIGraphicsBeginImageContextWithOptions should be called only on the main thread. When called it creates a bitmap-based context, which is ready to be manipulated either with CoreGraphics' functions or with methods like - drawInRect: for UIImage , -drawInRect:withFont: for NSString and so on. For CoreGraphics' drawing everything is clear - you pass a CGContextRef argument

CGContext text drawing doesn't scale up on iPhone 4

ⅰ亾dé卋堺 提交于 2019-12-03 07:33:22
I am trying to create an app that scales up nicely on the iPhone 4. Currently most of it scales up perfectly, except for one crucial piece: the text that I draw inside a CALayer, inside its drawInContext: method. Here is my code: - (void)drawInContext:(CGContextRef)context { UIGraphicsPushContext(context); CGContextSetGrayFillColor(context, 1.0f, 1.0f); CGContextFillRect(context, self.bounds); CGContextSetAllowsAntialiasing(context, true); CGContextSetShouldAntialias(context, true); CGContextSetAllowsFontSmoothing(context, true); CGContextSetShouldSmoothFonts(context, true);

In iOS, how can you programmatically fill out a pdf form field?

穿精又带淫゛_ 提交于 2019-12-03 07:21:09
I need to take an existing pdf file and programmatically fill in a list of form fields with text and then save the pdf without ever displaying it to the user. For instance, if the pdf file contains fields named "LastName", and "FirstName" I would like to set the value of "FirstName" to "Louis" and then save the file. I've been searching for a long time and can't find any guidance on even where to start since the iOS documentation (and most of the questions on here) seem geared towards displaying or creating pdf content instead of modifying it. EDIT: My main question is: Is it possible to open

UITableView with Transparent Gradient at Top and Bottom

本秂侑毒 提交于 2019-12-03 07:13:36
I have searched this forum, Google and other forums and have not found an the answer to my particular issue. Basically, I have a UIView which contains UITableView . I followed this tutorial and it was partially successful. The problem is the gradient. I have a background image behind the UITableView . So as the cell nears the gradient, I want the background to be showing, instead of the white. I also found this post which which is where I found the tutorial, but I didn't want to hijack that post with my own questions for matt. Any help in the right direction would be great! EDIT1: I know I can

How to flip coordinates when drawing in context?

梦想与她 提交于 2019-12-03 07:10:15
I create a context from an UIImage, and then I draw into it with CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), oImageRef); the image appears upside-down due to the flipped coordinate system in quartz. How can I fix that? You should be able to transform the context using something similar to the following: CGContextSaveGState(bitmapContext); CGContextTranslateCTM(bitmapContext, 0.0f, originalImage.size.height); CGContextScaleCTM(bitmapContext, 1.0f, -1.0f); // Draw here CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage