Thursday 12 March 2015

Image Popup in popover view : small popup in UIView

- (IBAction)btnShowImage:(UIButton*)sender
{
//    Declare below declaration in .h file
//    UIPopoverController  *popoverVC;
    
    
    if([popoverVC isPopoverVisible])
    {
        //close the popover view if toolbar button was touched
        //again and popover is already visible
        //Thanks to @chrisonhismac
        
        [popoverVC dismissPopoverAnimated:YES];
        return;
    }
    
    //build our custom popover view
    UIViewController* popoverContent = [[UIViewController alloc] init];
    
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
    
    popoverView.backgroundColor = [UIColor whiteColor];
    
    popoverContent.view = popoverView;
    
    
    
    ////-- show image in popover view
    GPImageView *imgView = [[GPImageView alloc] initWithFrame:CGRectMake(10, 10, 230, 230)];
    
    NSString *imgURL = [SiteAPIURL stringByAppendingFormat:@"resizeImage.php?width=460&height=460&imagename=%@", dictCustomer[@"photo"]];
    
    [imgView setImageFromURL:imgURL
       showActivityIndicator:YES
               setCacheImage:YES];
    
    [popoverView addSubview:imgView];
    
    
    
    //create a popover controller
    popoverVC = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    
    popoverVC.contentViewController.preferredContentSize =  CGSizeMake(250, 250);
    
    [popoverVC presentPopoverFromRect:sender.frame   // did you forget to call this method?
                               inView:self.view
             permittedArrowDirections:UIPopoverArrowDirectionLeft
                             animated:YES];
}

No comments:

Post a Comment