cocoa - Unexpected NSTextField background color, should be transparent -
update:
i've added sample project testing, see @ bottom of post.
original question:
i've got nswindow
, change background when other parameters change.
the window background gradient i'm drawing overriding drawrect
in subclass of window's view.
class mainwindowview: nsview { override func drawrect(dirtyrect: nsrect) { var rect = dirtyrect let gradient = nsgradient(startingcolor: backgroundcolor, endingcolor: darkerbackgroundcolor) gradient.drawinrect(rect, relativecenterposition: nspoint(x: 0, y: 0)) super.drawrect(rect) } }
and i've got 2 nstextfield
s on window.
the nstextfield
s both set drawsbackground = false
in awakefromnib
, set borderless
in ib.
i'm not using nsattributedstring
s here, changing stringvalue
of nstextfields, , of course textcolor
.
everything working... except sometimes, text fields have unexpected dark semi-transparent background.
(it's hard see on screens it's there.)
question: why darker background appear?
and of course: fix it?
i'm pretty sure it's gradient breaks can't find what...
note: project in swift can read objective-c answer.
edit:
so indeed seems coming gradient that's behind, see other screenshot test window. time gradient drawn in custom view under nstextview, , same undesired effect happens: parts of text field background visible shouldn't.
update:
i have made simple example in project testing, gradient shows phenomenon more visibly. there's window, gradient class , text field. can (30ko only) in this zip file.
you draw gradient in dirty rect. when text changes, rect size of textfield, not of whole view. drawrect function draws full gradient in textfield's background rect, rather portion of background-view-wide gradient you'd see through textfield.
if redraw using view's frame, , ignore dirty rect argument, should desired appearance.
Comments
Post a Comment