Tuesday, May 6, 2014

youtube video in iphone

http://stackoverflow.com/questions/15717754/objective-c-how-to-autoplay-a-youtube-video-in-a-uiwebview

Disappearing Keyboard on iPhone on touching anywhere on the UIView

#pragma mark - allow keyboard to dismiss by tapping anywhere not otherwise tappable on the view
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    LogDebug(@"touchesBegan:withEvent:");
    
  
   //-------------
  
    [super touchesBegan:touches withEvent:event];

}

Schedule Timer on iPhone apps

Function nameOfTheFunctionToBeCalled will be called after 6 secs.

NSTimeInterval timeInterval = 6; //seconds
        [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                         target:self
                                       selector:@selector(nameOfTheFunctionToBeCalled)
                                       userInfo:nil

                                        repeats:NO];


iPhone goes to sleep even with idleTimerdisabled=YES

Find the solution from here

If your application is using camera then app will go to sleep after using camera . So you need to add UIRequiredDeviceCapabilities in your app plist . Different devices you can add as shown here


After camera access, idletimerdisabled setting changed back to original



Monday, May 5, 2014

Changing Text Color of UICollectionViewCell on selection programmatically

Have to overwrite the setSelected method of UICollectionView Class. Don't forget to call super as well. 

-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
       self.tagLabel.textColor=[UIColor blackColor];
    }
    else
        
     self.tagLabel.textColor=[UIColor lightTextColor];
    

}

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");
}