Thursday 10 November 2011

UINavigationBar and UINavigationItem background image

UINavigationBarItem Background Image


navigationController.parentViewController action:@selector(yourmethod:)];
             self.navigationItem.leftBarButtonItem.image = [UIImage imageNamed:@"leftbar.png"];

UINavigationBar Background Image

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header.png"] forBarMetrics:UIBarMetricsDefault];



iOS Application starts from main method

iOS application starts from main method


int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}



int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
// If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.



Handle Orientation in iPhone/iPad


  
By default iOS5 and earlier supports only portrait mode orientation, if we want to enable all orientation we have to implement shouldAutorotateToInterfaceOrientation method in UIViewController.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES; //YES for supporting all orientation. NO- disable orientation
}

iOS have four orientations are 
   UIInterfaceOrientationPortrait
   UIInterfaceOrientationPortraitUpsideDown
   UIInterfaceOrientationLandscapeLeft    
   UIInterfaceOrientationLandscapeRight
if dont want any one orientation, then check the orientation and return NO

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    return NO; //disable UIInterfaceOrientationLandscapeLeft orientation
else
   return YES;
}

Find device orientation changes :-

//implement this method to find the device orientation changes - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { } If your application doesn't call didRotateFromInterfaceOrientation method then you have to add your controller as child view controller in then rootview controller. - (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController:(UIViewController*) self.yourChildController]; }

Changing UIView when Orientation change :-

Here i created two UIView and assigned when orientation changed. I created two dashboard UIView for portrait and landscape , get the IBOutlet from XIB 
Views.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight ) { self.view = self.LandscapeView; } else { self.view = self.portraitView; } return YES; }
Download the source code for better understanding : https://github.com/karthikprabhuA/iPhoneOrientationHandling



Launch iPhone/iPad email composer in your application


MFMailComposeViewController  class is used to editing and email, its present in MessageUI.framework.

canSendMail method is used to find whether the user has set up the device for sending email .

Here launched email composer in my application, presenting as a modal popover.

if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.navigationBar.tintColor = [UIColor redColor]; // your navigationbar color
mail.mailComposeDelegate = self;
[mail setSubject:@"Check out my iPhone/iPad app"];
[mail setMessageBody:@"<html><body>Check out <a href='http://karthik-prabhu.blogspot.in/'>iVerde</a></body></html>" isHTML:YES];
        //mail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
       // [self setModalPresentationStyle:UIViewAnimationOptionTransitionFlipFromTop];
            [self presentViewController:mail animated:YES completion:NULL ]; //presentModalViewController deprecated from iOS5 and above 
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"App name Message" message:@"Please setup at least One email account." delegate:self cancelButtonTitle:nil      otherButtonTitles: @"OK", nil];
[alert show];
[alert release];
}





Wednesday 2 November 2011

How to get iPhone iPad System Properties

UIDevice Class is used to get the phone name, model, localizedModel, systemname, system version,orientation,battery level etc.

  [[UIDevice currentDevicename]
  [[UIDevice currentDevice] model]
  [[UIDevice currentDevicelocalizedModel]
  [[UIDevice currentDevicesystemName]
  [[UIDevice currentDevicesystemVersion]
  [[UIDevice currentDeviceorientation]
  [[UIDevice currentDevicebatteryLevel]


The main advantage is to check the battery level ;

float btlevel = [[UIDevice currentDevice] batteryLevel]; // range is from 0.0 to 1.0 UIDeviceBatteryState btstate = [UIDevice currentDevice] batteryStatus];


iOS(iPhone and iPad) Application Development for Beginner




  • First you need to learn objective C basics.
  • Should know about the iOS Framework.
  • Should know how the iOS controller works like UIViewController,UITableviewcontroller, UINavigationControler,UITabBarcontroller etc. 
  • Do some homework with all the controls with xib and programatically then you will get a clear idea.
  • If you want to become a master dont skip the basics.
  • My advise is to start with stanford tutorial (pdf and video) for iOS5 (http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall and http://itunes.apple.com/us/itunes-u/ipad-iphone-application-development/id473757255).


Here I attached Stanford iOS basics tutorial


Stanford iOS development basics tutorial