app*_*eak 6 iphone uiimageview viewcontroller
我正在尝试将imageview的帧设置为图像的原始大小,并将其显示在视图的中心.我为此编写了以下代码,但图像仍然出现在整个屏幕上!假设图像大小为320x88,它显示调整大小/拉伸到320x460!我希望它出现在屏幕的中心,所以我将Y坐标设置为(460-88)/ 2,但它不起作用.有谁可以帮我解决这个问题.谢谢.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:filePath]];
if(imageView.image.size.width == IPHONE4_RES_WIDTH)
[imageView setFrame: CGRectMake(0, 0, imageView.image.size.width/2, imageView.image.size.height/2)];
UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
viewController.view.backgroundColor = [UIColor blackColor];
NSLog(@"%f : %f",viewController.view.bounds.size.height, imageView.bounds.size.height);
viewController.view = imageView;
viewController.view.contentMode = UIViewContentModeCenter;
[self.navigationController pushViewController:viewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
Rak*_*att 16
试试这个
viewController.view.contentMode=UIViewContentModeCenter;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8261 次 |
| 最近记录: |