2016-05-23 17 views
0

渲染图像视图中的所有边角角半径这是它的外观前:如何设置与UIGraphicsGetImageFromCurrentImageContext

enter image description here

后,我产生拖观点:

enter image description here

和这是我如何生成单元格的拖动视图:

private func setupDraggingViewForCell(cell: BWStudentWishlistBookCollectionViewCell) { 

    UIGraphicsBeginImageContextWithOptions(cell.bounds.size, false, 0) 
    cell.bookImageView.layer.renderInContext(UIGraphicsGetCurrentContext()!) 

    draggingView = UIImageView(image: UIGraphicsGetImageFromCurrentImageContext()) 
    draggingView?.clipsToBounds = true 
    draggingView?.contentMode = .ScaleAspectFit 
    draggingView?.layer.masksToBounds = true 
    draggingView?.layer.cornerRadius = 10 

    view.addSubview(draggingView!) 

    UIGraphicsEndImageContext() 
} 

正如您所看到的,只有一个圆角是圆角的。为什么?

+1

我认为你的拖动视图小于图像..你有剪辑绑定=是可能 –

+0

我认为你必须设置draggingView的框架(尤其是起源) –

回答

-1

不知道,但尝试圆形图像比ImageView的

func makeRoundedImage(image: UIImage, radius: Float) -> UIImage { 
    var imageLayer: CALayer = CALayer.layer 
    imageLayer.frame = CGRectMake(0, 0, image.size.width, image.size.height) 
    imageLayer.contents = (image.CGImage as! AnyObject) 
    imageLayer.masksToBounds = true 
    imageLayer.cornerRadius = 10 
    UIGraphicsBeginImageContext(image.size) 
    imageLayer.renderInContext(UIGraphicsGetCurrentContext()) 
    var roundedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 
    return roundedImage 
} 

,然后设置图像您图像视图。并清除dragableView的背景颜色

希望它会帮助..!

0

您可以将clipsToBounds设置为false,并且可能会解决您的问题。否则,它会向您显示封面的全部框架,然后您可以决定做什么。

draggingView?.clipsToBounds = false 
0

您可以直接否则这段代码添加到您的自定义单元格根据自己的需要.......

override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
     imageView.layer.shadowColor = UIColor.blackColor().CGColor 
     imageView.layer.shadowOpacity = 1 
     imageView.layer.cornerRadius = 5 
     imageView.layer.shadowOffset = CGSizeZero 
     imageView.layer.shadowRadius = 2 

//If you added Aspect to Fill 
     imageView.clipsToBounds = true 
    } 

我希望这将帮助你...(Y)

相关问题