我创建如下视图:
// Create sub view for Logo
logoView =[[UIView alloc] initWithFrame:CGRectMake(0,0,screen.size.width,(screen.size.height - 230))];
[logoView setBackgroundColor:[UIColor blueColor]];
UIImageView *bgLogoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-welcomeLogoView.png"]];
[logoView addSubview:bgLogoView];
//NSLog(@"the button view height is %f",(screen.size.height - 230));
logoView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
我有一个用于logoView的机顶盒。高度为230(iphone4
如何使该图像适合视图。目前,它会将完整尺寸的图像加载到实际上是该尺寸一半的块中...图像的质量提高了两倍。我正在运行ios5的iphone4上进行测试。
我敢肯定,由于某种原因,错过了一两行以使图像适合周围视图的视图范围。
最佳答案
尝试这个:
UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 230)];
NSString *bgFilePath = [[NSBundle mainBundle] pathForResource:@"bg-welcomeLogoView"
ofType:@"png"];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:bgFilePath];
[bgImageView setImage:img];
[logoView addSubview:bgImageView];
您可以在initWithFrame中更改UIImageView的大小: