quartz-graphics

How to draw a triangle programmatically

我们两清 提交于 2019-12-17 22:09:15
问题 I have a triangle solver, I want a way to use the values I get from the answer to draw a triangle to the screen that matches it. 回答1: If you subclass a UIView you can implement something like this in drawRect to draw a triangle: -(void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx); CGContextMoveToPoint (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect)); // top left CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMidY(rect)); // mid

CGColorGetComponents() not returning the correct values for black and for white

拟墨画扇 提交于 2019-12-17 16:55:13
问题 Has anyone experienced this problem? It looks like a bug in Apple's code and I will submit a radar if people agree that this code should do what I think it should do. I'm not all that familiar with CoreGraphics color management, hence I'm asking before I bug Apple with a bug report. This is straight out of a template project and the only non-template code is what you see below. Note that the red, green, and blue colors all show the correct component values but not white or black. The problem

NSAttributedString background color and rounded corners

放肆的年华 提交于 2019-12-17 02:27:10
问题 I have a question regarding rounded corners and text background color for a custom UIView . Basically, I need to achieve an effect like this (image attached - notice the rounded corners on one side) in a custom UIView: I'm thinking the approach to use is: Use Core Text to get glyph runs. Check highlight range. If the current run is within the highlight range, draw a background rectangle with rounded corners and desired fill color before drawing the glyph run. Draw the glyph run. However, I'm

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

Creating gradient and returning for a method

為{幸葍}努か 提交于 2019-12-14 01:37:24
问题 Sorry for noobish question about iPhone and Quartz programming. Just started my conversion from C++ to Objective-C :) So, I have such a class method +(CGGradientRef)CreateGradient:(UIColor*)startColor endColor:(UIColor*)endColor { CGGradientRef result; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[2] = {0.0f, 1.0f}; CGFloat startRed, startGreen, startBlue, startAlpha; CGFloat endRed, endGreen, endBlue, endAlpha; [endColor getRed:&endRed green:&endGreen blue:

Apply a Quartz filter while saving PDF under Mac OS X 10.6.3

本小妞迷上赌 提交于 2019-12-13 17:06:46
问题 Using Mac OS X API, I'm trying to save a PDF file with a Quartz filter applied, just like it is possible from the "Save As" dialog in the Preview application. So far I've written the following code (using Python and pyObjC, but it isn't important for me): -- filter-pdf.py: begin from Foundation import * from Quartz import * import objc page_rect = CGRectMake (0, 0, 612, 792) fdict = NSDictionary.dictionaryWithContentsOfFile_("/System/Library/Filters/Blue \ Tone.qfilter") in_pdf =

Can't draw shadow after clipping

房东的猫 提交于 2019-12-13 05:13:59
问题 I needed to draw a shadow around photos of users. I drew those circle photos by drawing a circle and then clipping the context. Here's the snippet of my code: + (UIImage*)roundImage:(UIImage*)img imageView:(UIImageView*)imageView withShadow:(BOOL)shadow { UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, [UIScreen mainScreen].scale); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddEllipseInRect(context, CGRectMake(0,0, imageView.width, imageView.height));

How to draw a triangle programmatically

旧时模样 提交于 2019-12-13 04:29:23
问题 I have a triangle solver, I want a way to use the values I get from the answer to draw a triangle to the screen that matches it. 回答1: If you subclass a UIView you can implement something like this in drawRect to draw a triangle: -(void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx); CGContextMoveToPoint (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect)); // top left CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMidY(rect)); // mid

CATiledLayer or CALayer drawing UIImage not working

ε祈祈猫儿з 提交于 2019-12-13 02:53:05
问题 Good day all; I am trying to manually (not using sublayers) draw images within a CATiledLayer but it is not behaving as it should with the defined solution. I undertand that when you call 'CGContextDrawImage' you must scale and translate so as to flip it but I cannot for the life of me, get it to work. I have a method called - (void)drawInContext:(CGContextRef)context Image:(UIImage *)image which is called several times from with in - (void)drawInContext:(CGContextRef)context to render all

Controlling level and focus of windows other apps with CGPrivate functions

自古美人都是妖i 提交于 2019-12-13 00:53:33
问题 Question How to use these private functions on other windows? It would be nice to have this knowledge back in the wild. I am specifically trying to get CGSOrderWindow and CGSSetWindowLevel to work. I was trying in the direction of: temporarily register as the dock and then register the dock as the dock again immediately afterwards or code injection into the Dock process per this comment: Also, the author of the above project seems determined to make all core functionality available as a