Mike
Mike

Reputation: 301

OS X app focus ring doesn't change

My app has 7 buttons. When it starts one of them (not the first) ha a blue ring around it. Clicking another button doesn't change that. I don't see any difference in the Attribute Inspector. Focus ring is set to default for all the buttons.

Setting the focus ring to 'None' for that button gives me what I want, but I don't understand why this one button is different.

Upvotes: 0

Views: 443

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90531

In System Preferences, Keyboard pane, Shortcuts tab, there's a pair of radio buttons controlling Full Keyboard Access. You have selected "All controls". This allows buttons (among other things) to have focus.

When a window is first put on screen, it will attempt to put the focus on the first control that will accept it. "First" is determined by the key loop. In most cases, an app doesn't bother setting a key loop and the window is configured to automatically calculate it, which it does based on reading direction, more or less (e.g. top down, left-to-right for English). So, it has picked your first button to give focus to.

As Jesse Rusak suggested in his comment, if you press Tab, focus will cycle to the next button and so forth.

If you want a different control to have initial focus, you can connect the window's initialFirstResponder outlet to that control in the NIB. Or you can set it programmatically before showing it (at some point after -awakeFromNib).

You can set your buttons to not show a focus ring, but that doesn't prevent them from being focused. Hitting the Space key will still press the focused button, even if it's not showing the focus ring. And pressing Tab will cycle to the next button, so you'd have to make the change to all of them.

Alternatively, you can set your buttons to refuse first responder. However, that prevents people who want/need to use the keyboard to navigate your UI from doing so (short of using VoiceOver or other accessibility technology).

Upvotes: 2

Related Questions