31

I am making a little application with three NSButtons with an image set. These buttons have no border nor background. However, when I click a button it turns into a gray rectangle.

How can I fix this? Thanks.

3 Answers3

71

Make your button type as NSMomentaryChangeButton.

[myBtn setButtonType:NSMomentaryChangeButton];

If you use NSMomentaryPushInButton then you may get gray rectangle over the button when click.

Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
  • And what else? Could you add some more informatio. Check this [metaSO question](http://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to-a-question) and [Jon Skeet: Coding Blog](http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx) on how to give a correct answer. – Yaroslav Oct 11 '12 at 11:59
  • 1
    Edited my answer. There is nothing more than this. – Ramaraj T Oct 11 '12 at 12:13
  • Doesn’t worked for me, instead @Sean’s answer is currently leading to the right direction. – ixany Nov 24 '16 at 10:08
  • FYI NSMomentaryChangeButton is now deprecated and replaced by NSButtonTypeMomentaryChange. – Eric McNeill Oct 22 '18 at 15:26
14

You should be able to adjust this by changing the state mask. To do so, check out the highlightsBy: and showsStateBy: properties of NSButtonCell - they are for setting the press effect and displaying the effect respectively. The applicable constants for these methods are in the NSCell reference page.

bobblebub
  • 33
  • 1
  • 10
Sean Rich
  • 2,338
  • 2
  • 20
  • 15
  • 5
    I was searching a long time for the flags. So here is the solution as an addendum (thx to Sean Rich very much for this help):[self.button.cell setShowsStateBy:NSPushInCellMask]; [self.button.cell setHighlightsBy:NSContentsCellMask]; if you change BOTH masks, only your graphics will be shown as specified in IB. – JackPearse Feb 24 '12 at 14:33
0

If you are using an NSBox, make sure your button inside of NSBox in the hierarchy. Then use 'momentary push in' as your button type. The button will dim when clicked but there will be no border.

When I used NSBox with NSButton on the same hierarchy level, I would see the border when clicked.

Randy
  • 1
  • 2