Showing posts with label UIImageview. Show all posts
Showing posts with label UIImageview. Show all posts

Thursday, 5 December 2013

Add UINavigationBar to modal UITableViewController

ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentModalViewController:navC animated:YES];
 
Now , you'll add UINavigation items over this viewcontroller
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YOUR_IMAGE_NAME_WITH_EXTENSION"]];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:nil];

Thursday, 10 October 2013

Image URL load via AFNetworking | Wait Indicator placed while loading URL on UIImageView | Exact width/height of image width/height

If you want to maintain the aspect ratio of an image, use contentMode=UIViewContentModeScaleAspectFit
contentMode=UIViewContentModeScaleAspectFill (if you want to use full layout) and masking with width or height, Make sure that use Bitwise operator used i.e UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight
* masking is working only upon if content mode is set.
* setImageWithURLRequest, use this function: 
#import "UIImageView+AFNetworking.h"
UIImageView *imgView = [[UIImageView alloc] init];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.clipsToBound = YES;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIActivityIndicatorView *loadingIndicator =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loadingIndicator.center=CGPointMake(150,75);
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"YOUR_URL"]];
[imgView addSubview:loadingIndicator];
[self.view addSubview:imgView];
[loadingIndicator setHidden:NO];
[loadingIndicator startAnimating];
[imgView setImageWithURLRequest :imageRequest placeholderImage:nil success:^(NSURLRequest *request,NSHTTPURLResponse *response,UIImage *image){
        [loadingIndicator setHidden:YES];
        [loadingIndicator stopAnimating];
        imgView.image = image;
       //Here you set your frame accordingly
        CGSize size = img.size;
        imgView.frame = CGRectMake(xOffset,yOffset,size.width,size.height);
}failure:^(NSURLRequest *request,NSHTTPURLResponse *response, NSError *error){
        [loadingIndicator setHidden:YES];
        [loadingIndicator stopAnimating];
}];

Wednesday, 14 December 2011

Touch/Tap Event on single Object in iPhone | Populate Custom MenuItems


#pragma mark TouchEvents
-(void) touchesBegan : (NSSet *)touches withEvent : (UIEvent *)event {

UITouch *touch = [[event allTouches]anyObject];

CGPoint touchLocation = [touch locationInView:self.view];
CGPoint origin = self.yourImgView.frame.origin;
CGFloat x2 = origin.x + self.yourImgView.frame.size.width;
CGFloat y2 = origin.y + self.yourImgView.frame.size.height;

/**
Touch Event only responds on Your ImageView
*/

if ((touchLocation.x >= origin.x && touchLocation.x <= x2) && (touchLocation.y >= origin.y && touchLocation.y <= y2))
    {

if ([touch tapCount] == 2) {

[self becomeFirstResponder];

/** Description
 * Create Custom UIMenu Item
 * If we want more Menuitems.So, we can take an array and selector on each items
 * setTargetRect : On which frame you want to tap and display menu item on it.
 * setMenuVisible: No Menu items to hide.
 * menuRect : Where you want to display menu items.
 */

UIMenuItem *menuPasteItem = [[UIMenuItem alloc] initWithTitle:@"Paste" action:@selector(YourMethodName1)];
UIMenuItem *menuCopyItem = [[UIMenuItem alloc] initWithTitle:@"Copy" action:@selector(YourMethodName2)];

UIMenuController *menuController = [UIMenuController sharedMenuController];

CGRect menuRect = CGRectMake(0,10,150,100);

[menuController setTargetRect:menuRect inView:self.yourImgView];
menuController.menuItems=[NSArray arrayWithObjects:menuPasteItem,menuCopyItem,nil];
[menuController setMenuVisible:YES animated:YES];

}


    }

}

#pragma mark BOOL operations

-(BOOL) canBecomeFirstResponder{

return YES;
}

-(BOOL) canPerformAction:(SEL)action withSender:(id)sender{

BOOL confirm = NO;

if (action == @selector(YourMethodName1))
confirm = YES;
if (action == @selector(YourMethodName2))
confirm = YES;

return confirm;

}


I love to write this post, it really helps for me.

Hope