Below is my drawRect function for a simple custom view. When I use
var h: CGFloat = 200
the view displays itself properly: a rectangle part of which is black, part of which is red. But when I use
var h: CGFloat = fractionalHeight*parentViewHeight
all I get is a black rectangle. If fractionalHeight
(a property of the view)
is 0.5, half of the rectangle should be red. The print statement confirms the fact
that h is what I think it should be. Hmmmmm? What's going on?
override func drawRect(rect: CGRect)
{
var ctx = UIGraphicsGetCurrentContext()
CGContextClearRect(ctx, rect);
let parentViewBounds = self.bounds
let parentViewWidth = CGRectGetWidth(parentViewBounds)
let parentViewHeight = CGRectGetHeight(parentViewBounds)
println ("w,h = \(parentViewWidth),\(parentViewHeight) ")
// CGContextClearRect(ctx, rect);
CGContextSetRGBFillColor(ctx, 0.0, 0.0, 0.0, 1); // black
CGContextFillRect(ctx, CGRectMake(0, 0, parentViewWidth, parentViewHeight));
println("in drawRect, fractionalHeight = \(fractionalHeight)")
var h: CGFloat = 200 // fractionalHeight*parentViewHeight
CGContextSetRGBFillColor(ctx, 1.0, 0.0, 0.0, 1); // red
CGContextFillRect(ctx, CGRectMake(0, 0, parentViewWidth, h))
println("in drawRect, h = \(h)")
}