I believe that masking the image is the best option. But if you had to rotate, transform, animate or want a clear background, you can do something like this:
Create a subview that represents the size of the image you want to display. Make sure its clipsToBounds is true and the position of the image, respectively.
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; //this is the part of the image you wish to see UIView *imageWindow = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 30, 30)]; imageWindow.clipsToBounds = YES; //your image view is the height and width of mainView and x and y is imageWindow - mainView. You can do this manually or put in calculations. UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(imageWindow.frame.origin.x - mainView.frame.origin.x, imageWindow.frame.origin.y - mainView.frame.origin.y, mainView.frame.size.width, mainView.frame.size.height)]; myImage.image = [UIImage imageNamed:@"1024x1024.png"]; [imageWindow addSubview:myImage]; [mainView addSubview:imageWindow]; [self.view addSubview:mainView];
Looking back at my code, I don't think that mainView necessary, and you can add imageWindow to self.view directly.
source share