Hello All.

I'm trying to use Core Graphics to draw to a UIView. I'm purposely avoiding 
using UIKit  drawing methods for UIView because I'd like to go deeper into 
drawing: i have a button whose push down implementation in the View Controller 
is:


let colorSpace = CGColorSpaceCreateDeviceRGB()

a = CGContext(data: nil, width: 100, height: 100, bitsPerComponent:             
 8,     bytesPerRow: 0, space: colorSpace, bitmapInfo:
        CGImageAlphaInfo.premultipliedLast.rawValue);
    a?.setFillColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.0);
    a?.fill(CGRect(x: 0, y: 0, width: 100, height: 100));



    let i = a?.makeImage();
    UIGraphicsPushContext(a!);



    let v1 = DGView(frame: CGRect(x: 0, y: 0, width: 500, height: 550));
    v1.tag = 100;
    v1.image = UIImage(cgImage: i!);
    self.view.addSubview(v1);
    self.view.viewWithTag(100)?.backgroundColor = UIColor.white;


when i push the button, a UIView subclass (DGView) pops up with white
  background. in the draw method of DGView, I added this code:


UIGraphicsPopContext();
    let c = UIGraphicsGetCurrentContext();
    c?.draw((c?.makeImage())!, in: CGRect(x: 0, y: 0, width: 100, height:

            100));


The problem is nothing is being drawn. Output should've been a red rectangle. I 
would really appreciate some guidance on this. Thanks.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to