我想以编程方式将UIImageView添加到我的模式视图控制器,并且图像根本不显示。我只看到白色背景。其余的工作正常,因为我能够加载或解散视图。我下面的代码:UIImageView(以编程方式创建)没有显示
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UIImageView *imageView = [[[UIImageView alloc] init] initWithFrame:CGRectMake(100, 200, 100, 100)];
imageView.image = [UIImage imageNamed:@"IMG_0352.PNG"];
[self.view addSubview:imageView];
UISwipeGestureRecognizer *swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
swipeleft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];
UISwipeGestureRecognizer *swiperight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
swiperight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swiperight];
UIBarButtonItem *dismiss_btn = [[UIBarButtonItem alloc] initWithTitle:@"Start App" style:UIBarButtonItemStylePlain target:self action:@selector(dismissModal:)];
self.navigationItem.rightBarButtonItems = [NSMutableArray arrayWithObjects:dismiss_btn, nil];
这应该工作...尝试为imageView添加backgroundColor以检查图像中显示的问题或者imageView –
全部大写的图像名称是否正确? – thorb65
除了@HaniIbrahim对背景颜色的建议外,我还会在这里推荐一些'NSLog'输出,检查'imageView.image'为null。 – nhgrif