cocoa - Change border "glow" color of NSTextField -


i have nstext field in mainmenu.xib , have action set validate email address. want nstexfields border color (that blue glow) red when action returns no , green when action returns yes. here action:

-(bool) validemail:(nsstring*) emailstring {     nsstring *regexpattern = @"^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$";     nsregularexpression *regex = [[nsregularexpression alloc] initwithpattern:regexpattern     options:nsregularexpressioncaseinsensitive error:nil];     nsuinteger regexmatches = [regex numberofmatchesinstring:emailstring options:0 range:nsmakerange(0, [emailstring length])];     nslog(@"%ld", regexmatches);     if (regexmatches == 0) {         return no;     } else         return yes; }   

i call function , setting text-color right now, set nstextfield's glow color instead.

- (void) controltextdidchange:(nsnotification *)obj{     if ([obj object] == emails) {         if ([self validemail:[[obj object] stringvalue]]) {             [[obj object] settextcolor:[nscolor colorwithsrgbred:0 green:.59 blue:0 alpha:1.0]];             [reviewbutton setenabled:yes];         } else {             [[obj object] settextcolor:[nscolor colorwithsrgbred:.59 green:0 blue:0 alpha:1.0]];             [reviewbutton setenabled:no];         }     } } 

i open sub-classing nstextfield, cleanest way appreciated!

the way go subclass nstextfieldcell , draw own focus ring. far can tell there's no way tell system draw focus ring using own color, you'll have call setfocusringtype:nsfocusringtypenone, check if control has first responder status in drawing method, , if draw focus ring using own color.

if decide use approach remember focus ring user defined style (blue or graphite), , there's no guarantee future versions of osx won't allow user change standard color red or green. it's focus ring drawing style change in future versions of osx, @ point you'll have update drawing code in order things right.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -