core-graphics

How to draw text inner shadow on Cocoa for Mac OS X

本小妞迷上赌 提交于 2019-12-21 05:23:07
问题 How do I draw an inner shadow on a text in Cocoa for Mac OS X? I am subclassing NSView to create a placeholder control with a gradient background and an inner shadowed text title over it. All current Core Graphics answers on stackoverflow seem to explain drawing text shadows on Cocoa Touch. 回答1: You might think too complicated. If I get your problem right, the only thing you actually want to do is to set the text style. Then do so by simply using: [[object cell] setBackgroundStyle

CGDisplayCopyAllDisplayModes leaves out one valid mode

梦想与她 提交于 2019-12-21 04:52:36
问题 When programmatically working with display modes in OS X (documentation), I've found that the CGDisplayCopyAllDisplayModes leaves out the rightmost option that is presented in System Preferences. A simple utility that prints the size of the current display mode and all available display mode sizes outputs this current size: 1920x1200 available sizes: 2880x1800 1440x900 2560x1600 2048x1280 1024x768 800x600 640x480 1680x1050 1280x800 1920x1200 is a valid option All of the other options that

iOS - Clipping union of two paths using UIBezierPath appendPath

a 夏天 提交于 2019-12-21 04:39:12
问题 I'm attempting the create a clipping path in the shape of a plus sign, so that subsequent paths that I draw into the same context have this portion removed. I create the clipping path using two rectangle paths overlaid on each other. This is what I'd like the final drawing to look like when I subsequently draw a circle: xXX| |XXx XXXX| |XXXX XXXXX| |XXXXX ——— ——— ——— ——— XXXXX| |XXXXX XXXX| |XXXX xXX| |XXx However, it actually looks like this: xXX| |XXx XXXX| |XXXX XXXXX| |XXXXX ——— XX——— ———

Only White Fill Color is Transparent in UIView

♀尐吖头ヾ 提交于 2019-12-21 04:17:07
问题 I've got a UIView that is set to opaque = NO and it all works nicely. In the drawRect I'm doing custom drawing, and this works CGContextSetFillColor(context, CGColorGetComponents([UIColor blueColor].CGColor)); CGContextFillRect(context, labelOutside); CGContextAddRect(context, labelOutside); but this CGContextSetFillColor(context, CGColorGetComponents([UIColor whiteColor].CGColor)); CGContextFillRect(context, labelOutside); CGContextAddRect(context, labelOutside); results in NO fill being

OSX/Swift: Call function when screen becomes available

孤者浪人 提交于 2019-12-21 04:09:09
问题 I want my OSX app to call a function when the user's screen becomes available, ex: their computer wakes from sleep or the user turns on their screen. Basically any time the user goes from having no screen active to having one active, I would like my function to be called. I'm not sure if the best way to do this is to: Check for changes in sleep/wake state or Use CGDisplayReconfigurationCallback or Listen for a NSWorkspaceScreensDidWakeNotification Which of these seems like the best way to do

Bitwise operations with CGBitmapInfo and CGImageAlphaInfo

醉酒当歌 提交于 2019-12-21 04:03:12
问题 I'm having trouble performing bitwise operations with CGImageAlphaInfo and CGBitmapInfo in Swift. In particular, I don't know how to port this Objective-C code: bitmapInfo &= ~kCGBitmapAlphaInfoMask; bitmapInfo |= kCGImageAlphaNoneSkipFirst; The following straightforward Swift port produces the somewhat cryptic compiler error 'CGBitmapInfo' is not identical to 'Bool' on the last line: bitmapInfo &= ~CGBitmapInfo.AlphaInfoMask bitmapInfo |= CGImageAlphaInfo.NoneSkipFirst Looking at the source

Drawing text over Core Graphics in Swift 3

妖精的绣舞 提交于 2019-12-21 03:39:25
问题 Background: I am drawing on a UIImageView with Core Graphics. I would like to ultimately draw a text string over the core graphics drawing. This (hackingwithswift.com) method i used to draw the text to an image, set my imageView to that image, and then draw over with core graphics. But I want the text to overlay the core graphics drawing. Now I have moved to this https://stackoverflow.com/a/35574171/6337391 but it still isnt allowing me to write on top of my drawing. class MapViewController:

Doing completely custom animations with Core Animation - performance

放肆的年华 提交于 2019-12-21 02:52:32
问题 The article https://www.objc.io/issues/12-animations/animating-custom-layer-properties/ has this to say about doing completely custom animations with Core Animation: Suppose that instead of implementing our clock face using individual layers, we wanted to draw the clock using Core Graphics. (In general this will have inferior performance , but it’s possible to imagine that there are complex drawing operations that we might want to implement that would be hard to replicate using ordinary layer

Drawing Circular Gradient

吃可爱长大的小学妹 提交于 2019-12-21 02:43:13
问题 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

How to create UIBezierPath gradient fill?

旧城冷巷雨未停 提交于 2019-12-21 02:42:26
问题 I would like to create a UIBezierPath with 10px rounded corners and with gradient fill. How can I acheive this effect? Here's an image of what I want to do: As you can see, this square has: 2px black border 10px rounded corners red to green linear gradient fill How can I do this programatically without using pattern image color ? Here's how I create the path: UIBezierPath *border = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10.0f]; [border setLineWidth:2]; [[UIColor