简体   繁体   中英

Quartz 2D drawing RGB in alpha faded UIView

I've created a custom UIView which overrides the drawRect method using Quartz. I've eventually managed to get everything working exactly how I want it to however there is a really peculiar behaviour which I can't get my head around.

If I use the custom UIView defined as => (@interface TagView : UIView) with it's alpha value set to 1 then it draws exactly as I would expect it to.

The problem I've come across is that in one particular instance I want it to draw at an alpha of 0.3 so I've added the view to IB with an alpha of 0.3. I draw a number of artifacts with different RGB values set using CGContextSetRGBStrokeColor and CGContextSetRGBFillColor. These all work fine until I try and set a non-zero value for all 3 RGB values.

To illustrate if I use: CGContextSetRGBStrokeColor(context, 1, 1, 0, 1); then I get a yellow line. If I use: CGContextSetRGBStrokeColor(context, 1, 1, 0.001, 1); I get nothing at all.

It seems like as long as I set one of the RGB values to 0 it's happy and draws but as soon as all three values are non-zero it fails. Also this is all working fine when the alpha of the view is set to 1.0 (ie I can draw white without any issues whatsoever).

Does anyone have any thoughts or suggestions as to what might be causing this or how I might diagnose the problem?

Garrrrrrr... It seems my mystical ability to post a question on a forum ONLY to work it out myself 30 seconds later has struck again! (of course this is after 2 1/2 days of pulling hair out...).

It seems I had accidentally left the background colour of the view as white. With 0.3 alpha it wasn't actually very obvious. White on white == invisible so i suspect that's why the lines weren't visible. I would have thought that the ALMOST yellow would have shown up but that doesn't seem to be the case.

尝试将自定义视图的opaque属性设置为NO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM