How to draw segmented control with blue tint like Xcode?

两盒软妹~` 提交于 2019-11-30 15:15:40

Segmented Control - with on-state appearance

Use an NSSegmentedControl object with style NSSegmentStyleTexturedRounded and mode NSSegmentSwitchTrackingSelectAny.

  • Place a Segmented Control object in your toolbar or bottom bar
  • In the Attributes pane of the inspector, set the style to Textured Rounded and the mode to Select Any.
  • Be sure to provide an image for the control (in Interface Builder, select an image from the Image combo box in the Attributes inspector).


Toggle-Style Toolbar Button

The way in which this is achieved for single buttons differs slightly from that of segmented controls:

  • Use an image with the name IconTemplate or Template appended to its (original) name
  • Select the NSTexturedRoundedBezelStyle Button Style

↳ For example I have three .png images in my resources, MiddlePanelIconTemplate.png, CardPanelIconTemplate.png, and ReturnPanelIconTemplate.png using Round Textured Button Cell Style.

OS X Human Interface Guidelines | Window-Frame Controls

Answer provided by 'L'l worked ok for me, but appending IconTemplate to your image name it's not working on Xcode 7.3 anymore. Instead of that, you have to go to your Assets catalog, choose the image you want to use and on the right panel you have to select the Attributes Inspector and on the combo that says 'Render As' select 'Template Image'.

To make an NSButton programmatically (macOS 10.13 / Xcode 9) with Blue Tint when ON and not when OFF (like some of the buttons in Xcode toolbar) I do the following:

  1. Add PNG to asset catalog with transparent background and white line drawing (pdf with black lines also works).
  2. Set image in asset catalog to render as "template" (setting is in right sidebar).
  3. Set only 1 image (do not use alternate image) or will not work.
  4. bezelstyle = NSTexturedRoundedBezelStyle.
  5. buttontType = NSToggleButton.
  6. yourButton.cell.controlTint = NSBlueControlTint (on) or NSDefaultControlTint (off) according to state.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!