我有一些 .png,它们是 iPhone 的屏幕截图。
我想将它们显示在 UIImageView 和按钮中,如何缩小它们,以便它们适合 View /按钮的大小,但所有内容仍然可见。
我目前正在做这样的事情:
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"screenshot.png"]];
view.frame = CGRectMake(0.0f, 0.0f, 200, 200);
view.clipsToBounds = YES;
或
UIImage *image = [UIImage imageNamed:@"carouselPage.png"];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake(0.0f, 0.0f, 200, 200);
button.clipsToBounds = YES;
如果我使用其他.png(较小),那么它们就会出现,但如果我使用screenshot.png(通过Xcode的组织器屏幕截图功能获得),则什么也不会出现
最佳答案
您需要设置图像的缩放比例,以确保全部显示并适合 View
view.contentMode = UIViewContentModeScaleAspectFit;
我认为您仍然应该看到 snapshot.png,但只是不正确。
关于ios - 如何缩小屏幕截图以适应较小的 View 或按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806174/