2016-04-28 93 views
-1

我試圖給一個圖像視圖的背景只有白色。以下是我的代碼。無法僅爲UiImageView設置背景

dataArray = [[NSMutableArray alloc] init]; 
    [dataArray addObject:@"Knowledge"]; 
    [dataArray addObject:@"Client"]; 

    float screenWidth = [UIScreen mainScreen].bounds.size.width; 
    float pickerWidth = screenWidth * 3/4; 

    float xPoint = screenWidth/2 - pickerWidth/2; 

    pickerView = [[UIPickerView alloc] init]; 
    pickerView.transform = CGAffineTransformMakeScale(1, 1); 
    [pickerView setDataSource: self]; 
    [pickerView setDelegate: self]; 
    [pickerView setFrame: CGRectMake(xPoint, 200.0f, pickerWidth, 200.0f)]; 
    pickerView.showsSelectionIndicator = YES; 
    [pickerView selectRow:2 inComponent:0 animated:YES]; 

    UIImageView *imageview = [[UIImageView alloc] 
           initWithFrame:CGRectMake(30, 20, 300, 400)]; 
    [imageview setImage:[UIImage imageNamed:@"logo.png"]]; 
    [imageview setContentMode:UIViewContentModeScaleAspectFit]; 
    [imageview setBackgroundColor: [UIColor whiteColor]]; 
    [self.view addSubview:imageview]; 
    [self.view addSubview: pickerView]; 

林面臨兩個問題,而這樣做,

  1. 被施加兩者的UIImageView和UiPickerView背景顏色認爲我已經具體指定[imageview的setBackgroundColor:的UIColor whiteColor]];何時必須僅用於UiImage。
  2. 雖然我給出了合適的座標,但手機處於橫向模式時,對齊方式發生了變化。我怎樣才能解決這個問題?
+0

什你想要嗎?在這裏,您將背景顏色設置爲imageview的白色,並且沒有任何錯誤。那麼isse是什麼? – Lion

+0

正在爲pickerview和imageview設置白色背景 –

回答

1

集pickerview的背景色一樣,

pickerView.backgroundColor = [UIColor lightGrayColor]; //desired color 

希望這將有助於:)

+0

否我已更新我的問題,屏幕截圖 –

+0

我沒有正確地獲取您的需求?你想要什麼?你需要白色背景pickerview? – Lion

+0

不....我想imageview的白色背景。 –

1

試試這個代碼:

imageView.backgroundColor = [UIColor clearColor]; 
imageView.opaque = NO; 
1

試試這個: -

UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]]; 
[self.view addSubview:backgroundView];