2015-04-21 62 views
0

我在iPhone 6上拍攝了一張屏幕截圖,並將其放入iPhone 6模擬器中。我通過呈現一個imagePicker控制器挑選圖像,然後將其設置在didFinishPcikingMediaWithInfo如下:從圖庫照片中導入屏幕截圖並設置爲Xcode 6.3中的背景Swift

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { 
    self.dismissViewControllerAnimated(true, completion: nil); 

    let refImage = info[UIImagePickerControllerOriginalImage] as! UIImage 

    self.view.backgroundColor = UIColor(patternImage: refImage) 
} 

這導致在這樣的顯示: iPhone6 Simulator size wrong

我還試圖改變最後一行是:

let frame = CGRectMake(0, 0, image.size.width, image.size.height) 
let backgroundView = UIImageView(frame: frame) 
backgroundView.image = image 
backgroundView.contentMode = .ScaleAspectFill 
self.view.addSubview(backgroundView) 

和還試圖 backgroundView.contentMode = .ScaleAspectFit

任何想法爲什麼截圖的大小加倍,似乎不適合?我猜測某種解決方案問題?

回答

1

更改此

let frame = CGRectMake(0, 0, image.size.width, image.size.height) 

let frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) 

如果這不起作用,並且您使用故事板然後拖放一個UIImageView,將其連接至IBOutlet中,然後設置你的UIImage。