86481

How to change the focus ring color?

Question:

In the draw function of the NSImageView,I want to set my custom focus ring color,not the default blue color.I tried as follows code

NSSetFocusRingStyle(NSFocusRingOnly); [[NSColor redColor] setStroke]; NSRectFill([self bounds]);

But the color is still default blue color.How can I solve this problem?

update: The NSShadow class help me to accomplish adding focus ring.It's easy to change the shadow color.

NSShadow *shadow = [[[NSShadow alloc] init] autorelease]; [shadow setShadowBlurRadius:5]; [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; [shadow setShadowColor:[NSColor redColor]]; [shadow set];

I code this in the NSImageView's draw function.

Answer1:

The only way to solve this "problem" is to draw the focus ring yourself. The NSFocusRingStyle code is designed to make it easy for you to draw a focus ring in the user's selected focus style, which includes them being able to set the focus ring color.

It is by design that you cannot easily change the focus ring color, as it is part of the OS theme and thus should be under the user's control (according to the HIG). If you have a special case, such as needing to adaptively color the focus ring based on the contents of the image, you will have to create your own focus ring from scratch.

Recommend

  • Create Drop Shadow for NSView - Cocoa
  • How to make NSView's background image not repeat?
  • How to vertically and horizontally center a div of unknown height
  • adding item to window Extjs 4
  • LCD Programming with Arduino
  • How to parsing NSDate to RFC 822 always use in English?
  • iOS Date formatting
  • branch out of range compile error
  • Drag and reorder - UICollectionview with sections
  • Error while re-opening sound file in python
  • css calendar - td background diagonal split - two colors
  • Java: java.util.ConcurrentModificationException
  • GKLeaderboardViewController initial leaderboard
  • iOS 6 dateFromString returns wrong date
  • “A GKScore must specify a leaderboard.”
  • Emacs lua-mode issue: (void-function interactively-called-p)
  • Create function that can pass a parameter without making a new component
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • How can we prepend rows to a react native list-view?
  • Knockout custom binding handler
  • Question about instantiating object
  • NSScanner Loop Question
  • Pass value from viewmodel to script in zk
  • Join two tables and save into third-sql
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • How to model a transition system with SPIN
  • Eraser for UIBezierPath
  • ORA-29908: missing primary invocation for ancillary operator
  • Compare two NSDates in iPhone
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Load html files in TinyMce
  • Understanding cpu registers
  • Java static initializers and reflection
  • Add sale price programmatically to product variations
  • unknown Exception android
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • Converting MP3 duration time