Sunday, November 1, 2015

Colour-Memory 4*4 grid project

The goal of this work sample is to construct a sample memory game called ”Colour Memory”. The game board consists of a 4x4 grid with 8 pairs of color cards.

 Here is a list of things I used to create this sample.

1) Use of sqlite database  and interaction class 
2) subclassing of UITableViewCell
3) subclassing of UIButton
4) Use of Auto Layout in iOS


UIButton subclassing is used to store the state of that button
and used to store the image name that we need to set as a image when user taps on that button.
It also contain animation code of flip view from left to right and right to left.
Here is a code to flip the UIButton and show image.

You can find this code in below given link.
Name of the file is ColorUIButton
 -(void)showButtton  
 {  
 self.userInteractionEnabled = false;  
 [UIView transitionWithView:self duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{  
 //code to change the image of UIButton  
 } completion:^(BOOL finished) {  
 self.userInteractionEnabled = true;  
 }];  
 }  







UITableViewCell is used to handle the row of 4 UIButtons
 It handle all the interaction done on UIButton.

You can find this code in below given link.
Name of the file is ColorCell


















Download full code from GitHub

Saturday, October 31, 2015

Twitter Integration in iOS

Twitter Integration using SLRequest 

 1) Ask user to access its twitter account

  ACAccountStore *accountStore = [[ACAccountStore alloc] init];  
   ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
   [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {  
     if(granted) {  
            //User allowed to access account  
     }}];  

2) Get all twitter accounts from list

 ACAccountStore *store = [[ACAccountStore alloc] init];  
   ACAccountType *AccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
  NSArray *accountsArray = [store accountsWithAccountType:AccountType];  

3)get particular Account from Accounts array.

 -(ACAccount *)getTwitterAccount:(NSString *)aStrUserName  
 {  
   ACAccountStore *store = [[ACAccountStore alloc] init];  
   ACAccountType *AccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
   __weak ACAccount *selAccount = nil;  
   NSArray *accountsArray = [store accountsWithAccountType:AccountType];  
   for (ACAccount *myaccount in accountsArray) {  
     if([myaccount.username.lowercaseString isEqualToString:aStrUserName.lowercaseString])  
     {  
       selAccount = myaccount;  
       break;  
     }  
   }  
   return selAccount;  
 }  

Thursday, October 29, 2015

How to add image in UINavigationBar in iPhone app

How to add image in UINavigationBar in iPhone app

 +(void)setNavigationBarAppearance{  
   [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"image name.png"] forBarMetrics:UIBarMetricsDefault];  
   [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:  
                              [UIColor whiteColor], NSForegroundColorAttributeName,  
                              [UIFont fontWithName:@"Font name" size:17.0], NSFontAttributeName,nil]];  
 }  

To set title view of UINavigationBar use below code

 viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];  


How to disable back swipe gesture in UINavigationController on iOS
From iOS 7 Apple added a new default navigation behavior. You can swipe from the left border of the screen to go back on the navigation stack.
So, It is possible to disable this new gesture in UINavigationController.
Just add this online code and thats it.

  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])  
     [self.navigationController.view removeGestureRecognizer:self.navigationController.interactivePopGestureRecognizer];  

OR

  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])  
   self.navigationController.interactivePopGestureRecognizer.enabled = false;  


The edgesForExtendedLayout property, together with the extendedLayoutIncludesOpaqueBars property, determines whether or not view controllers' views underlap top and bottom bars (navigation bar, toolbar)
Extenedges- iOS
This is useful when you are using Storyboard and UINavigationBar & you want to start counting frame after UINavigationBar ends with autolayout.
so just select checkbox of Extenedges - Under top bars and thats it.