quartz-graphics

Can't add a corner radius and a shadow

可紊 提交于 2019-11-27 10:57:19
I'm trying to draw a shadow and a corner radius on an image. I can add them separately, but I've got no way to add both effects at the same time. I'm adding a shadow with: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; Here, layer is a CALayer of a UIView subclass. So this works whenever I set [layer setMasksToBounds:NO]; Now to add a corner radius I do this: [layer setCornerRadius:7.0f]; but I need to set MasksToBounds to YES in order for this to work: [layer setMasksToBounds:YES]; Is there anyway I can get

How to fill a path with gradient in drawRect:?

霸气de小男生 提交于 2019-11-27 09:11:25
问题 filling a path with a solid color is easy enough: CGPoint aPoint; for (id pointValue in points) { aPoint = [pointValue CGPointValue]; CGContextAddLineToPoint(context, aPoint.x, aPoint.y); } [[UIColor redColor] setFill]; [[UIColor blackColor] setStroke]; CGContextDrawPath(context, kCGPathFillStroke); I'd like to draw a gradient instead of solid red, but I am having trouble. I've tried the code listed in the Question/Answer: Gradients on UIView and UILabels On iPhone which is: CAGradientLayer

What's the difference between Quartz Core, Core Graphics and Quartz 2D?

China☆狼群 提交于 2019-11-27 09:10:21
问题 I wonder if someone can distinguish precisely between these? For my understanding, Core Graphics is just a "Framework Package" which contains Quartz Core and Quartz 2D. But I'm not sure about if Quartz 2D actually is Quartz Core? Maybe someone can draw some lines there? What makes up the differences between these? When looking at the documentation, I see Quartz Core is listing up all the Core Animation stuff only. So Quartz Core == Core Animation? 回答1: From the Quartz 2D Programming Guide:

CGEventPost - possible bug when simulating keyboard events?

℡╲_俬逩灬. 提交于 2019-11-27 07:08:29
I have a very simple chunk of code that is designed to simulate keyboard events. The simple example below should type "Cz" - the shift key goes down, the c key goes down, c comes up and shift comes up. Then the z key goes down and up. It seems that sometimes the order gets muddled though. When I create a timer to call this routine every second, the output should be CzCzCzCz.... But here's what I get: CZcZCZCzczCzczCzczCZCZCzCz I'll run it again: CzCzCzCzCZCzCZCzCZCzCZCzCZCzCzCz Different. And equally wrong. The code: e1 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)56, true); CGEventPost

Releasing CGImage (CGImageRef)

天大地大妈咪最大 提交于 2019-11-27 06:23:40
问题 I'm curious if I'm following proper memory management with CGImageRef, which I'm passing through several methods (since it's CG object, I assume it doesn't support autorelease). Memory management with non-NSObjects and interaction with other NSObjects is still somewhat new to me. Here what I'm doing: I'm creating the CGImageRef inside my image cache manager with CGBitmapContextCreateImage (retain count 1), and adding it to the NSMutableDictionary (retain count 2). When CALayers use the image,

How can I get a list of all windows, currently on the screen, in swift?

不问归期 提交于 2019-11-27 05:49:35
问题 How can I get a list of all windows, currently on the screen, in swift ? (all examples are preceded by import Cocoa ) In objective-c I can run the following code successfully: CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); But when I run the equivalent in swift (using the playground to test): let windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kcGNullWindowID) I get an error telling me that I have an Use of

What are some great Quartz 2D drawing tutorials? [closed]

﹥>﹥吖頭↗ 提交于 2019-11-27 05:05:23
问题 I'm searching for some great Quartz 2D drawing tutorials aimed at the iPhone. I'm new to Quartz and want to start off with something easy and then progress to more difficult stuff. Does anyone know of any Quartz 2D drawing tutorials that they would recommend? 回答1: I devoted an entire class to Quartz 2D drawing last semester in my advanced iPhone development course. The video for that is available on iTunes U, along with the rest of the class. The course notes for that session can be found

CGImageRef Memory leak

霸气de小男生 提交于 2019-11-27 03:31:37
问题 I'm having a memory leak when using this custom method which returns a CGImageRef. I can't release "cgImage" properly because I have to return it. What chould I do ? - (CGImageRef)rectRoundedImageRef:(CGRect)rect radius:(int)radius { CGSize contextSize = CGSizeMake(rect.size.width, rect.size.height); CGFloat imageScale = (CGFloat)1.0; CGFloat width = contextSize.width; CGFloat height = contextSize.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context =

How to remove black edge on UIImageView with rounded corners and a border width?

血红的双手。 提交于 2019-11-27 03:30:51
问题 I have the following code to make the UIImageView in each of my UITableView's cells have rounded corners: - (void)awakeFromNib { // Rounded corners. [[cellImage layer] setCornerRadius:([cellImage frame].size.height / 2)]; [[cellImage layer] setMasksToBounds:YES]; [[cellImage layer] setBorderColor:[[UIColor whiteColor] CGColor]]; [[cellImage layer] setBorderWidth:3]; // Trouble! } I want the images to have a bit of a gap between them, and figured I could make use of the border width to make

How to draw a rounded rectangle in Core Graphics / Quartz 2D?

烈酒焚心 提交于 2019-11-27 02:57:49
I need to draw an outline for a rounded rectangle. I know I can make lines and arcs, but maybe there is also a function for rounded rects? Instead of making your own path out of lines and arcs, you can use [UIBezierPath bezierPathWithRoundedRect:cornerRadius:] or [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:] (the second one lets you specify which corners are rounded) Available in iOS 3.2 or later. There is no prepackaged way to this, you must combine arcs in order to do this, apples quartzdemo project shows the code to do this, here is a reference Quartz Demo and here