Friday, 15 March 2013

disable ARC for a single file in a project IOS


It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.
You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box.

Reference- http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project

How to Convert UIView to PDF within iOS?




-(IBAction)mailaspdf{
    
    [self createPDFfromUIView:self.view saveToDocumentsWithFileName:@"myPdf.pdf"];
}


-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
Reference- http://stackoverflow.com/questions/5443166/how-to-convert-uiview-to-pdf-within-ios

Wednesday, 6 March 2013

Tap and Swipe Gesture iPhone

Single tap Gesture. 

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)];
    singleTap.numberOfTapsRequired = 1;
    [self.view addGestureRecognizer:singleTap];


- (void)doSingleTap{

}

Swipe Left Gesture and Swipe Right

 UISwipeGestureRecognizer *swipeLeftGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftGesture:)];
    swipeLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeftGestureRecognizer];
    // [swipeLeftGestureRecognizer release];
    
    UISwipeGestureRecognizer *swipeRightGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGesture:)];
    [self.view addGestureRecognizer:swipeRightGestureRecognizer];


- (void)swipeLeftGesture:(UISwipeGestureRecognizer *)sender{
}

- (void)swipeRightGesture:(UISwipeGestureRecognizer *)sender{
   
    //[self.navigationController popViewControllerAnimated:YES];
}

Tuesday, 5 March 2013

Horizontal scrolling buttons in iPhone


   IBOutlet UIScrollView *scrollView1;
    UIButton *button;

const CGFloat kScrollObjHeight = 110;
const CGFloat kScrollObjWidth = 110.0;
const NSUInteger kNumImages = 7;



- (void)viewDidLoad
{
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scrollView1.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 0; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"pt%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
//UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        
        
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
        
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self
                   action:@selector(aMethod:)
         forControlEvents:UIControlEventTouchDown];
        // [button setTitle:@"Show View" forState:UIControlStateNormal];
        [button setImage:image forState:UIControlStateNormal];
        //button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
        // [view addSubview:button];
        
        
CGRect rect = button.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
button.frame = rect;
        button.tag=i;
//imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:button];
//[imageView release];
}
[self layoutScrollImages];
    
    
}



- (void)layoutScrollImages
{
UIButton *view = nil;
NSArray *subviews = [scrollView1 subviews];
    
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc =0;
for (view in subviews)
{
if ([view isKindOfClass:[UIButton class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}




-(void)aMethod:(id)sender{
    
    
    UIButton *but=(UIButton *)sender;
    NSLog(@"Hee %d",but.tag);
    if(but.tag==1){
        
   

        }else if(but.tag==2){
        pp1ViewController * viewController = [[pp1ViewController alloc] initWithNibName:@"pp1ViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:NO];
        
       
    }else if(but.tag==3){
       }    
}