UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(twoByThreeTap:)]; tap.numberOfTapsRequired = 2; tap.numberOfTouchesRequired = 3; [self addGestureRecognizer: tap]; [tap release];If you're not getting taps, perhaps you're using a default UIImageView, you'll probably need to turn on interaction and multitouch, either in IB or in code:
// So we can get the taps. self.userInteractionEnabled = YES; self.multipleTouchEnabled = YES;
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView: self]; if (CGRectContainsPoint(self.bounds, point)) { NSLog (@"YAY!"); } } // touchesEnded
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(startStop:)]; singleTap.numberOfTapsRequired = 1; singleTap.numberOfTouchesRequired = 1; [self addGestureRecognizer: singleTap]; UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(resetTimer:)]; doubleTap.numberOfTapsRequired = 2; doubleTap.numberOfTouchesRequired = 1; [self addGestureRecognizer: doubleTap]; [singleTap requireGestureRecognizerToFail: doubleTap]; [singleTap release]; [doubleTap release];
BOOL haveSecondScreen = [UIScreen screens].count > 1; if (haveSecondScreen) { UIScreen *screen = [[UIScreen screens] objectAtIndex: 1]; // Figure out the largest screen mode we can use. CGSize max = CGSizeMake (0.0, 0.0); UIScreenMode *maxScreenMode = nil; for (UIScreenMode *mode in [screen availableModes]) { if (mode.size.width * mode.size.height > max.width * max.height) { max = mode.size; maxScreenMode = mode; } } screen.currentMode = maxScreenMode; UIView *view = [[UIView alloc] initWithFrame: screen.bounds]; view.backgroundColor = [UIColor greenColor]; UIWindow *window = [[UIWindow alloc] init]; window.screen = screen; [window addSubview: view]; window.hidden = NO; [view release]; // Stash |window| into an ivar or something. }This doesn't deal with stuff like aspect ratios, etc.
self.groovyView.layer.cornerRadius = 5; self.groovyView.layer.borderColor = [[UIColor purpleColor] CGColor]; self.groovyView.layer.borderWidth = 1; self.groovyView.layer.masksToBounds = YES;
#import <QuartzCore/QuartzCore.h> // For layer styles ... textview.layer.borderWidth = 1.0f; textview.layer.borderColor = [UIColor blackColor].CGColor;
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event; - (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event; - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event; - (void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event;
@interface BlahView : UIView @end @implementation BlahView - (void) drawRect: (CGRect) rect { CGRect bounds = self.bounds; UIColor *color = [UIColor colorWithRed: (((int)self >> 0) & 0xFF) / 255.0 green: (((int)self >> 8) & 0xFF) / 255.0 blue: (((int)self >> 16) & 0xFF) / 255.0 alpha: 1.0]; [color set]; UIRectFill(bounds); [[UIColor blackColor] set]; UIRectFrame(bounds); } // drawRect @end // BlahView ... CGRect frame = CGRectMake(200, 5, 300, 30); BlahView *view = [[BlahView alloc] initWithFrame: frame]; [viewController.view addSubview:view];And here is the version for Cocoa-non-touch:
@interface BlahView : NSView @end @implementation BlahView - (void) drawRect: (CGRect) rect { CGRect bounds = self.bounds; NSColor *color = [NSColor colorWithDeviceRed: (((int)self >> 0) & 0xFF) / 255.0 green: (((int)self >> 8) & 0xFF) / 255.0 blue: (((int)self >> 16) & 0xFF) / 255.0 alpha: 1.0]; [color set]; NSRectFill(bounds); [[NSColor blackColor] set]; NSFrameRect (bounds); } // drawRect @end // BlahViewAnd for Swift/Cocoa-touch:
func prettyColor(thanks to Step Christopher for the translation)(instance: T) -> UIColor { var address = unsafeBitCast(instance, Int.self) let red = CGFloat(address >> 0 & 0xFF) / 255.0 let green = CGFloat(address >> 8 & 0xFF) / 255.0 let blue = CGFloat(address >> 16 & 0xFF) / 255.0 let derivedColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0) return derivedColor }