2016-04-21 53 views
0

我有畫它使用平局矩形內芯圖像一個UIButton:更改繪製按鈕的ImageView

enter image description here

我需要用的UIImageView再次重繪註釋後:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
    if let ImageFromCamera = info[UIImagePickerControllerOriginalImage] as? UIImage { 
     let ImageView = UIImageView() 
     ImageView.image=ImageFromCamera 
     ImageView.frame=personalImage.frame 
     ImageView.layer.cornerRadius = self.pickedImage.frame.size.width/2 
     ImageView.clipsToBounds = true 
     ImageView.layer.borderWidth = 12.0 
     ImageView.layer.borderColor = UIColor.whiteColor().CGColor 
     // change the custom drawn button "personalImageButton" to imageView 
    } 
    dismissViewControllerAnimated(true, completion: nil) 

} 

回答

0

您在設置圖像並禁用該功能時仍然使用按鈕

personalImageButton.setImage(ImageView, forState: .Normal) 
personalImageButton.enabled = false 
0

有沒有辦法將UIImageView分配給UIButton。繞過它的一種可能的方法是創建一個透明按鈕並將其放在UIImageView上。但在你的情況下,你似乎根本不需要UIImageView。使用setBackgroundImage設置按鈕的圖像,然後使用yourButton.layer進行調整。

+0

如何刪除以前繪製的按鈕? –