How to Get the Display Name with the Display ID in Mac OS X?

This gives you the localized display name: static void KeyArrayCallback(const void* key, const void* value, void* context) { CFArrayAppendValue(context, key); } – (NSString*)localizedDisplayProductName { NSDictionary* screenDictionary = [[NSScreen mainScreen] deviceDescription]; NSNumber* screenID = [screenDictionary objectForKey:@”NSScreenNumber”]; CGDirectDisplayID aID = [screenID unsignedIntValue]; CFStringRef localName = NULL; io_connect_t displayPort = CGDisplayIOServicePort(aID); CFDictionaryRef dict = (CFDictionaryRef)IODisplayCreateInfoDictionary(displayPort, 0); CFDictionaryRef names … Read more

Can’t add a corner radius and a shadow

Yes, yes there is… If you want both a corner radius and a drop shadow, you don’t turn on -masksToBounds, but rather set the corner radius and set the bezier path of the shadow with a rounded rect. Keep the radius of the two the same: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; … Read more

Applying a Gradient to CAShapeLayer

You could use the path of your shape to create a masking layer and apply that on the gradient layer, like this: UIView *v = [[UIView alloc] initWithFrame:self.window.frame]; CAShapeLayer *gradientMask = [CAShapeLayer layer]; gradientMask.fillColor = [[UIColor clearColor] CGColor]; gradientMask.strokeColor = [[UIColor blackColor] CGColor]; gradientMask.lineWidth = 4; gradientMask.frame = CGRectMake(0, 0, v.bounds.size.width, v.bounds.size.height); CGMutablePathRef t = … Read more

How to write a web-based music visualizer?

Making something audio reactive is pretty simple. Here’s an open source site with lots audio reactive examples. As for how to do it you basically use the Web Audio API to stream the music and use its AnalyserNode to get audio data out. “use strict”; const ctx = document.querySelector(“canvas”).getContext(“2d”); ctx.fillText(“click to start”, 100, 75); ctx.canvas.addEventListener(‘click’, … Read more

iPhone – Draw transparent rectangle on UIView to reveal view beneath

You have to override the top view’s drawRect method. So, for example, you might create a HoleyView class that derives from UIView (you can do that by adding a new file to your project, selecting Objective-C subclass, and setting “Subclass of” to UIView). In HoleyView, drawRect would look something like this: – (void)drawRect:(CGRect)rect { // … Read more

Drawing rotated text with NSString drawInRect

I solve this problem in next way. 1) Declare category on NSString @interface NSString (NMSchemeItemDraw) -(void) drawWithBasePoint:(CGPoint)basePoint andAngle:(CGFloat)angle andFont:(UIFont*)font; @end This category will draw text with given central point, in one line and with given font and angle. 2) Implementation of this category is looks like: @implementation NSString (NMSchemeItemDraw) -(void) drawWithBasePoint:(CGPoint)basePoint andAngle:(CGFloat)angle andFont:(UIFont *)font{ CGSize … Read more