Showing only a portion of the original image in a UIImageView
ios, objective-c, uiimageview
Solution
If you added the UIImageView form XIB, you can find a "mode" property there and then you can see and set different modes from there (from Interface builder). Or by programatically, you can set different modes by
imageView.contentMode = UIViewContentModeCenter;
imageView.clipsToBounds = YES;
Problem
How can i show only a portion of the original image in a UIImageView This question may be very familiar and old, But the reason for asking again is,i could not find a workable idea with the help of those answers Many said set image.contentMode = UIViewContentModeCenter; (but not working) I need almost a rectangle containing the center of the original image,How do I get this ? I do make this working,when i am displaying a static image to my app and setting Content mode of UIImageVie as Aspect Fill. But this is not workable in the case when i am displaying an image from url and using NSData Adding my code and the images ``` NSString *weburl = @"http://topnews.in/files/Sachin-Tendulkar_15.jpg"; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 50, 108, 86)]; NSURL *url = [NSURL URLWithString:weburl]; NSData *data = [NSData dataWithContentsOfURL:url]; imageView.image = [UIImage imageWithData:data]; [self.view addSubview:imageView]; ```