core-graphics

Mac OS X: Convert between NSView coordinates and global screen coordinates

三世轮回 提交于 2020-01-12 12:01:49
问题 I have the following situation in my multi-monitor setup: In this example I want to position a window exactly at the coordinates depicted with the yellow arrow. All I do have however, are the coordinates of an NSView that is a subview of the contentView of an NSWindow that spans the entire (bigger,upper) secondary monitor. Here's how the global coordinate space is defined: {0,0} is the coordinate of the upper left corner of my laptop screen. (green) {-296, -1080} is the coordinate of the

draw a line in UIImageView problem

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 11:11:56
问题 In my application i can draw a line in a UIImageView by the code below,and i want redraw the line even longer when i call the function,however,the output come out is not as expected,it will just draw a new line and remove the old one,the length is remain the same jus the y position different,i dont know which line of my code is wrong or i havent understand the CGContext class in correct way,please help i have scratch my head all the days and cannot find out the problem - (void) drawLine {

draw a line in UIImageView problem

谁说我不能喝 提交于 2020-01-12 11:11:10
问题 In my application i can draw a line in a UIImageView by the code below,and i want redraw the line even longer when i call the function,however,the output come out is not as expected,it will just draw a new line and remove the old one,the length is remain the same jus the y position different,i dont know which line of my code is wrong or i havent understand the CGContext class in correct way,please help i have scratch my head all the days and cannot find out the problem - (void) drawLine {

CGContext rotation

北城余情 提交于 2020-01-12 03:56:09
问题 I have a 100x100 pixel image that I want to draw at various angles rotated around the center of the image. The following code works, but rotates around the original origo of the coordinate system (upper left hand corner) and not the translated location. Thus the image is not rotated around itself but around the upper left corner of the screen. The following code was run in a custom view in a blank application with nothing else but this. - (void)drawRect:(CGRect)rect { CGContextRef context =

Circular UIView with multiple coloured border working like a pie chart

六眼飞鱼酱① 提交于 2020-01-11 12:14:12
问题 I am trying to set a circular avatar of a player of a game with a piechart representation on the avatar's circular border. Player 1 - Wins 25% Lost 70% Drawn 5% cell.selectedPhoto.frame = CGRectMake(cell.selectedPhoto.frame.origin.x, cell.selectedPhoto.frame.origin.y, 75, 75); cell.selectedPhoto.clipsToBounds = YES; cell.selectedPhoto.layer.cornerRadius = 75/2.0f; cell.selectedPhoto.layer.borderColor=[UIColor orangeColor].CGColor; cell.selectedPhoto.layer.borderWidth=2.5f; cell.selectedBadge

UIEdgeInsets ignored on CGContextDrawImage within a UIGraphicsBeginImageContextWithOptions

亡梦爱人 提交于 2020-01-11 06:00:26
问题 I am struggling getting Image Insets to work when drawing to an off screen buffer. Using the resizableImageWithCapInsets: on an UIImage directly setImage: into a button works fine for me: UIImage * base = [UIImage imageNamed:@"button.png"]; UIImage * img = [base resizableImageWithCapInsets:UIEdgeInsetsMake(20,20,20,20)]; [self setImage:img forState:UIControlStateNormal]; As shown below (left is raw scaling, right is scaled with insets): So the right one is fine - the lines top/botton/left

How to Animate CoreGraphics Drawing of Shape Using CAKeyframeAnimation

ⅰ亾dé卋堺 提交于 2020-01-10 10:51:03
问题 I am trying to animate the drawing of a UIBeizerPath (in my example a triangle) in a UIView subclass. However, the entire subview is animating instead of the shape. Is there something I am missing with the animation? - (void)drawRect:(CGRect)rect { CAShapeLayer *drawLayer = [CAShapeLayer layer]; drawLayer.frame = CGRectMake(0, 0, 100, 100); drawLayer.strokeColor = [UIColor greenColor].CGColor; drawLayer.lineWidth = 4.0; [self.layer addSublayer:drawLayer]; UIBezierPath *path = [UIBezierPath

How to make a conical gradient in iOS using Core Graphics / Quartz 2D?

梦想与她 提交于 2020-01-09 10:23:45
问题 How can I draw such a conical gradient in iOS using Core Graphics / Quartz 2D API? (source: ods.com.ua) 回答1: If anyone is still looking for a solution, Apple finally introduced .conic gradient type in iOS 12. Perfect for masking to create circular progress bar with gradient. Example: let gradientLayer = CAGradientLayer() gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.5) gradientLayer.endPoint = CGPoint(x: 0.5, y: 0) gradientLayer.type = .conic gradientLayer.colors = [UIColor.red.cgColor,

CGContextDrawPDFPage taking up large amounts of memory

…衆ロ難τιáo~ 提交于 2020-01-09 03:20:08
问题 I have a PDF file that I want to draw in outline form. I want to draw the first several pages on the document each in their own UIImage to use on a button so that when clicked, the main display will navigate to the clicked page. However, CGContextDrawPDFPage seems to be using copious amounts of memory when attempting to draw the page. Even though the image is only supposed to be around 100px tall, the application crashes while drawing one page in particular, which according to Instruments,

Simulating selected tab bar effect

北城余情 提交于 2020-01-07 04:40:49
问题 Partly as a programming exercise, and partly because we may need to include such images in an app some day, I've been trying to figure out how to draw an image like the selected tab in a UITabBar . The basic operation is simple enough in concept: the icon's alpha is used as a mask to draw the blue gradient image onto the tab. (Though I can't for the life of me figure out how one actually uses an image's alpha as a mask in Core Graphics. I ended up drawing the gradient first, then using a