Tuesday, April 29, 2014

Passing int as parameter to UIGestureRecognizer

Tag attribute is the key

-----------------

int i;
for(i = 0; i < count; i++) {
    // some image
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    // attach to some view
    imageView.tag = i;
 
    UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc]
                                    initWithTarget: self
                                           action: @selector(imageTap:)];
    [imageView addGestureRecognizer:g];
}
 
// handler
- (void)imageTap:(UITapGestureRecognizer *)sender {
  // identifier can be referenced in sender.view.tag

UIImageView *imageView = (UIImageView *)sender.view;

}

Friday, April 25, 2014

Iphone version detection

#define IS_DEVICE_RUNNING_IOS_7_AND_ABOVE() ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
#define iPhone4Or5oriPad ([[UIScreen mainScreen] bounds].size.height == 568 ? 5 : ([[UIScreen mainScreen] bounds].size.height == 480 ? 4 : 999))
Now in programming you can say...
if (IS_DEVICE_RUNNING_IOS_7_AND_ABOVE()) {
    NSLog("This is iOS 7");
} else {
    NSLog("This is iOS 6 or below");
}


if (iPhone4Or5oriPad==4) {
    NSLog("This is 3.5 inch iPhone - iPhone 4s or below");
} else if (iPhone4Or5oriPad==5) {
    NSLog("This is 4 inch iPhone - iPhone 5 & above");
} else {
    NSLog("This is iPad");
}