我想以編程方式將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