0

我有一些 .png,它们是 iPhone 的屏幕截图。

我想在 UIImageView 和按钮中显示它们,如何缩小它们以使其适合视图/按钮的大小,但所有内容仍然可见。

我目前正在做这样的事情:

    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 的 Organizer 截图功能获得),则什么都不会出现

4

1 回答 1

1

您需要设置图像的缩放比例以确保它全部显示并适合视图

view.contentMode = UIViewContentModeScaleAspectFit;

我假设您仍然应该看到 screenshot.png,但只是不正确。

于 2012-05-29T20:33:19.937 回答