如何绘制带有类似Xcode的蓝色调的分段控件? [英] How to draw segmented control with blue tint like Xcode?
问题描述
我正在尝试重新创建Xcode中使用的分段控件,在该控件中以蓝色调绘制图像。
I'm trying to recreate the segmented control used in Xcode where the images are drawn with a blue tint.
例如在Interface Builder中:
For example in Interface Builder:
到目前为止,我有一个自定义的 NSSegmentedCell
覆盖了-(void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView: (NSView *)controlView
,但是我仍然停留在如何绘制分段图像(1)带有灰色调和(2)带有蓝色调的情况下。
So far I have a custom NSSegmentedCell
overriding - (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView
, but I'm stuck at how to draw the segment image (1) with the gray tint and (2) with the blue tint if it is selected.
此外,看起来图像是用边框或渐变效果绘制的。当我自己绘制分段图像时,它只是黑色(因为我使用的是模板图像)。
Also, it looks like the images are drawn with a bezel or gradient effect. When I draw the segment image myself it is simply black (because I use template images).
如何从上方重新创建分段?
How can I recreate the segment from above?
推荐答案
分段控制-具有状态显示
使用 NSSegmentedControl
样式为 NSSegmentStyleTexturedRounded
且模式为 NSSegmentSwitchTrackingSelectAny
的对象。
Segmented Control - with on-state appearance
Use an NSSegmentedControl
object with style NSSegmentStyleTexturedRounded
and mode NSSegmentSwitchTrackingSelectAny
.
- 在您的工具栏或底部栏中放置分段控件对象
- 在属性窗格中检查器,将样式设置为圆角纹理,并将模式设置为选择任意。
- 确保为控件提供图像(在Interface Builder中,从图像组合框中选择一个图像)。属性检查器。)
单个按钮的实现方式与分段控件的实现方式略有不同:
The way in which this is achieved for single buttons differs slightly from that of segmented controls:
- 使用带有在其(原始)名称后附加名称
IconTemplate
或Template
- 选择
NSTexturedRoundedBezelStyle
按钮样式
- Use an image with the name
IconTemplate
orTemplate
appended to its (original) name - Select the
NSTexturedRoundedBezelStyle
Button Style
↳例如,我的资源中有3张 .png
图片,MiddlePanelIconTemplate.png,CardPanelIconTemplate.png ,以及使用圆形纹理按钮单元格样式的ReturnPanelIconTemplate.png。
↳ For example I have three .png
images in my resources, MiddlePanelIconTemplate.png, CardPanelIconTemplate.png, and ReturnPanelIconTemplate.png using Round Textured Button Cell Style.
这篇关于如何绘制带有类似Xcode的蓝色调的分段控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!