我正在嘗試將圖像添加到我的視圖中。我嘗試下面的代碼:以編程方式創建UIImageView
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tag40pixelsborder.png"]];
imgView.frame = CGRectMake(200, 200, 30, 30);
// imgView.bounds = CGRectMake(300, 300, 32, 32);
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:imgView];
NSLog(@"frame x %f", imgView.frame.origin.x);
NSLog(@"frame y %f", imgView.frame.origin.y);
但圖片不顯示在屏幕上,並返回的NSLog 30.00「x」和0.00「Y」如果我取消了邊界線和我刪除了框線「80」爲「x」,80.00爲「y」。
我使用autolayout,但完全相同的代碼在另一個視圖上工作!怎麼了?
你的圖像的尺寸是多少? – slecorne
該代碼適用於我,你添加圖像到xcode檢查圖像的拼寫 – Yohan
我複製 - 粘貼圖像的名稱,我敢肯定它是好的。 – anthoprotic