iphone - 图像正好在 iPad 的中间

标签 iphone objective-c ios ios4

我遇到了问题,我试图在屏幕中间显示图像 UIView *用户 View 。

 userView = [[UIView alloc] initWithFrame:CGRectMake(x, y, KVWDT, KVHGT)];//KVWDT=300 & KVHGT=400.

我的 ImageView 只显示在用户 View 的上半部分,在底部我还显示了一些其他字段

NSString *imageName = [NSString stringWithFormat:[dic objectForKey:@"img"]];  
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect imgFrame = imageView.frame;

我应该如何准确地在 userView 的中间显示图像。请帮我解决这个问题

最佳答案

使用:

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeCenter
imageView.center = userView.center;

关于iphone - 图像正好在 iPad 的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8645056/

相关文章:

上传后 iOS UIImagePickerController 结果视频方向

iphone - UITabBarController UITabBarItems 放在左边但一个在右边

iphone - SBJSON 解析器在第二次尝试时不起作用

ios - 无法在 cloudant DB 中更快地获取数据

ios - 无法符号化 iOS 应用程序崩溃报告我做了所有可能的有效场景。 iOS 应用程序符号化失败有哪些可能

iphone - 如何修改我的代码以允许用户将 UIImage 定位在 UIImageView 上?

iphone - 使用 iOS-libarchive 库提取 .tar 文件时出现问题

ios - iPhone 应用程序在某些设备上启动时崩溃,但在其他设备上运行

iphone - 如何将属性设为私有(private)?

iphone - 如何将 .sqlite3/.sqlite 文件导入 ios 应用程序?