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

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

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

How to create a colored 1×1 UIImage on the iPhone dynamically?

You can use CGContextSetFillColorWithColor and CGContextFillRect for this: Swift extension UIImage { class func image(with color: UIColor) -> UIImage { let rect = CGRectMake(0.0, 0.0, 1.0, 1.0) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() CGContextSetFillColorWithColor(context, color.CGColor) CGContextFillRect(context, rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } } Swift3 extension UIImage { class func image(with color: UIColor) -> … Read more

How to convert ASCII character to CGKeyCode?

This is what I ended up using. Much cleaner. #include <CoreFoundation/CoreFoundation.h> #include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */ /* Returns string representation of key, if it is printable. * Ownership follows the Create Rule; that is, it is the caller’s * responsibility to release the returned object. */ CFStringRef createStringForKey(CGKeyCode keyCode) { … Read more

iPhone smooth sketch drawing algorithm

CGPoint midPoint(CGPoint p1, CGPoint p2) { return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5); } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; previousPoint1 = [touch previousLocationInView:self]; previousPoint2 = [touch previousLocationInView:self]; currentPoint = [touch locationInView:self]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; previousPoint2 = previousPoint1; previousPoint1 … Read more

Get PDF hyperlinks on iOS with Quartz

heres the basic idea to get to the annots CGPDFDictionary for each page atleast. after that you should be able to figure it out with help from the PDF spec from Adobe. 1.) get the CGPDFDocumentRef. 2.) get each page. 3.) on each page, use CGPDFDictionaryGetArray(pageDictionary, “Annots”, &outputArray) where pageDictionary is the CGPDFDictionary representing the … Read more

tech