我正在尝试创建一个弹出我的xcode应用程序的框,只显示该大小的图像。我有以下
UIImageView *newView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach.jpg"]];
但这会创建完整尺寸的图像并显示它。我怎么只在50以上和200下降时显示为100w 100h?我会使用CGRect吗?
另外,我可以点击它使它消失吗?
编辑#1 我不想调整图像的大小 - 宁愿只拉出100平方像素并将它们放在一个帧中。
答案 0 :(得分:76)
请尝试使用以下代码。
MyImageview.contentMode = UIViewContentModeScaleAspectFill;
MyImageview.clipsToBounds = YES;
答案 1 :(得分:15)
您可以使用以下代码裁剪图片:
CGRect cropRegion = CGRectMake(50, 200, 100, 100);
UIImage *image = [UIImage imageNamed:@"beach.jpg"];
CGImageRef subImage = CGImageCreateWithImageInRect(image.CGImage, cropRegion);
UIImage *croppedImage = [UIImage imageWithCGImage:subImage];
UIImageView *newView = [[UIImageView alloc] initWithImage:croppedImage];
答案 2 :(得分:13)