【发布时间】:2015-07-17 19:02:29
【问题描述】:
我创建了一个 ViewController,然后将 ImageViewController 附加到它上面。 这是我的接口和实现。当我运行他们的程序时,它不显示图像,只有一个空白视图。
#import <UIKit/UIKit.h>
@interface ImageViewController : UIViewController
@property (nonatomic, strong) UIImageView *myImageView;
@end
实现
#import "ImageViewController.h"
@interface ImageViewController ()
@end
@implementation ImageViewController
@synthesize myImageView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//create an image
//create an image
UIImage *myScreenShot = [UIImage imageNamed:@"lips_PNG6197.png"];
//image view instance to display the image
self.myImageView = [[UIImageView alloc] initWithImage:myScreenShot];
//set the frame for the image view
CGRect myFrame = CGRectMake(10.0f, 10.0f, self.myImageView.frame.size.width,
self.myImageView.frame.size.height/2);
[self.myImageView setFrame:myFrame];
//If your image is bigger than the frame then you can scale it
[self.myImageView setContentMode:UIViewContentModeScaleAspectFit];
//add the image view to the current view
[self.view addSubview:self.myImageView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
请注意,我在调试器中检查了 UIImage 不是 nil。我也不是通过 IB 创建 UIImageView 。 关于出现问题的任何建议,即为什么我没有看到图像。
【问题讨论】:
标签: ios uiimageview uiimage