ios - Transparent view is black? -
i'm trying create view transparent in spots see image behind. however, reason in transparent part of view, i'm seeing black, instead of what's behind view. i've trimmed down little code , don't understand why transparent view shows black instead of red (the color of view behind). here's code:
class viewcontroller: uiviewcontroller { override func viewwillappear(_ animated: bool) { super.viewwillappear(animated) let redview = uiview(frame: view.frame) redview.backgroundcolor = uicolor.red let transparentview = transparentview(frame: view.frame) view.addsubview(redview) view.addsubview(transparentview) } }
class transparentview: uiview { override func draw(_ rect: cgrect) { uicolor.clear.setfill() uirectfill(rect) }
i expect screen full red, instead shows full black. before says it's lot easier make clear view, i'm trying more complex things in drawrect, dropped down basic thing try debug problem. missing here?
use self.isopaque = false;
make view/layer transparent when drawrect
overriden.
class transparentview: uiview { override init(frame: cgrect) { super.init(frame: frame); self.isopaque = false; //use this.. } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } override func draw(_ rect: cgrect) { uicolor.clear.setfill() uirectfill(rect) } }
Comments
Post a Comment