3

I have a view defined like this :

class TriangleView: UIView {


override func drawRect(rect: CGRect) {

    // Get Height and Width
    let layerHeight = self.layer.frame.height
    let layerWidth = self.layer.frame.width

    // Create Path
    let bezierPath = UIBezierPath()

    bezierPath.moveToPoint(CGPointMake(0, 0))
    bezierPath.addLineToPoint(CGPointMake(0, layerHeight))
    bezierPath.addLineToPoint(CGPointMake(layerWidth, layerHeight + 4))
    bezierPath.addLineToPoint(CGPointMake(0, 0))
    bezierPath.closePath()

    // Apply Color
    UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 1.0).setFill()
    bezierPath.fill()

    // Mask to Path
    let shapeLayer = CAShapeLayer()
    shapeLayer.borderColor = UIColor.clearColor().CGColor
    shapeLayer.path = bezierPath.CGPath
    self.layer.mask = shapeLayer

}

}

I'm trying to make it semi-transparent, however using UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 0.5).setFill() as well as using bezierPath.fillWithBlendMode( .Normal, alpha: 0.5) produces the same result of a darker than normal color with no transparency, the more I decrease the alpha in both cases, the darker the color becomes. I'm not sure what I'm doing wrong.

Alk
  • 5,215
  • 8
  • 47
  • 116

2 Answers2

4

Set the views backgroundColor to UIColor.clearColor().

Viktor Simkó
  • 2,607
  • 16
  • 22
0

I think you are assigning the TriangleView for the main view which present on the ViewController. Instead of that drag another view from the Object Library and assign it as TriangleView

Naveen Kumar H S
  • 1,304
  • 16
  • 30