Posts

Showing posts from 2012

Code to capture screenshot in iOS

This is method which take the screenshot of you current screen in iOS - ( UIImage *)captureView:( UIView *)view { CGRect rect = [[ UIScreen mainScreen ] bounds ]; UIGraphicsBeginImageContext (rect. size ); CGContextRef context = UIGraphicsGetCurrentContext (); [view. layer renderInContext :context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); return img; }

How to create simple webservice in php using JSON

Type the following code in your notepad save it with .php extension. and now run it from your browser. <?php $con=mysql_connect("localhost","root",""); if(!$con) { die("Error"); } mysql_select_db("webservice",$con); /* Data Fetch Query [Select Query to fetch data from any table] */ $sql="Select * from webservice"; $result=mysql_query($sql); $post=array(); while($row=mysql_fetch_assoc($result)) { $post[]=$row; } print_r(json_encode($post)); ?>

Programming fox: How to set background color of navigation bar in i...

Programming fox: How to set background color of navigation bar in i... : just type the following code in - viewDidLoad method     UIView *naview=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];    ...

How to scroll view up on keyboard appear

you should use this code to scroll the view on keyboard appear Basically whenever you want to enter some text on the textfield a default keyboard appear over the view sometimes what happen whenever the textfield present at the bottom of screen so at that type you will not be able to visible it. Here is the way to make it visible. first of all you need to inherit the UITextFieldDelegate protocol in your .h file and after that in your code make the textfield delegate to its file owner or use this code textField.delegate= self; and override this methods s -( BOOL )textFieldShouldBeginEditing:( UITextField *)textField {     NSTimeInterval animationDuration = 0.300000011920929 ;     CGRect frame = self . view . frame ;     y =textField. frame . origin . y ;     frame. origin . y =- y ;     frame. size . height += y ;     [ UIView beginAnimations : @"ResizeForKeyboard" context : nil ];   ...

How to set background color of navigation bar in iPhone

just type the following code in - viewDidLoad method     UIView *naview=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];       naview.backgroundColor = [UIColor colorWithRed:112/255.f green:50/255.f blue:19/255.f alpha:255/255.f];     UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(80, 5, 200, 25)];     titleLabel.textColor=[UIColor colorWithRed:255/255.f green:255/255.f blue:215/255.f alpha:255/255.f];     [titleLabel setBackgroundColor:[UIColor clearColor]];     titleLabel.text=@"title";     [naview addSubview:titleLabel];     [self.navigationController.navigationBar addSubview:naview];

How to set Rounded corner in imageView in iPhone

include this header file #import <QuartzCore/QuartzCore.h> CALayer *layer=imageView.layer; add this code in viewDidLoad [layer setMasksToBounds:YES]; [layer setCornerRadius:10.0];

Code to find Machine ID or IMEI in iPhone

[[UIDevice currentDevice] uniqueIdentifier];

Restrict the instantiation of class

Hi Friends If you want to restrict the Object Creation , i.e if you want that no object should be created more than one just go make the constructor of that class  private Example in Java class Sample { static int i=0; Sample() { if(i>0) throw new Exception("Object of this class cannot create more than One"); i++; } } class Main { public static void main(String[] arg) { try { Sample s1=new Sample();           /*Line 1*/ Sample s2=new Sample();           /*Line 2*/ } catch(Exception) { System.err.println("Object cannot create more than one"); } } } Line 1 will instantiate and object and Line 2 will generate and exception.