问题标签 [nssegmentedcontrol]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
680 浏览

cocoa - 带有粗体、斜体和下划线的 NSSegmentedControl

我正在尝试构建一个分段控件,非常类似于 TextEdit 中的粗体/斜体/下划线控件。

有没有办法为每个段设置自定义属性字符串?[set attributedStringValue:]对单元格没有影响(无论如何都无法设置每个段)。

如果我不得不求助于自定义绘图,我怎样才能在选定状态下重现插入/蓝色突出显示?

例子: 分段控制示例

0 投票
1 回答
1143 浏览

objective-c - 如何设置 NSSegmentedControl 背景图像?

我想设置NSSegmentedControl背景图像而不是图标图像。我将其子类化NSSegmentedCell并重写drawSegment: inFrame: withView:函数。但这很糟糕。我该怎么做?

更新:我想设置半矩形深色或浅色背景图像。

0 投票
1 回答
1027 浏览

macos - 如何制作均匀分布的 NSSegmentedControl?

我有一个 NSSegmentedControl 我想设置宽度,我希望这个控件填充我给它的所有空间。此外,我希望 NSSegmentedControl 的段在所有段之间均匀分布(独立于可用空间或内容)。我怎样才能做到这一点?

提前致谢。

0 投票
1 回答
1186 浏览

objective-c - Xcode 4 等工具栏中的 NSSegmentedControl

我想实现一个 NSSegmentedControl,就像 XCode 4 工具栏(视图或编辑器)中的那些。我无法调整其中的图像,也无法使用 Interface Builder 设置框架。最好的策略是什么?

0 投票
1 回答
368 浏览

objective-c - 如何调整 NSSegmentControl 的高度?

NSSegmentControl 的高度无法调整。

有没有人知道怎么做?

请告诉我。非常感谢。

0 投票
1 回答
1096 浏览

cocoa - NSSegmentedControl(NSSegmentCell 子类)文本颜色

我为 Sourcelist 创建了一个NSSegmentedControl多重徽章。第一段为绿色,显示匹配不同规则的项目数。第二段为红色并计算不匹配的规则。这NSSegmentedControl是禁用的,因此用户无法单击它。文本颜色是灰色的,因为它被禁用。

如何更改文本颜色?我尝试使用“setAttributedStringValue:”方法在 NSSegmentCell 子类中设置颜色,但它不起作用。

0 投票
2 回答
1673 浏览

cocoa - 如何自定义 NSSegmentedControl 字体和背景颜色

我想为 NSSegmentedControl 自定义背景颜色和文本颜色。可以选择为 IOS 执行此操作,但没有为 OSX 找到任何内容。

0 投票
0 回答
1055 浏览

ios - ios分段控制。具有不同颜色的文本和色调的多行标签

我目前正在尝试实现一个 UISegmentedControl,它使用与边框不同的文本颜色,但也跨越多行。

我已经设法使用这个问题来分别工作

UISegmentedControl 中的两行文本

并使用外观代理作为文本颜色:

但是,一旦我将这两种解决方案结合起来,我就会失去多线能力!我尝试将代码按不同的顺序放置,因此我在使用外观代理后循环遍历标签,但这不起作用。我也尝试过使用带有 NSLineBreakByWorkWrapping 的 lineBreakingMode 的自定义 NSParagraphStyle ,但这也不起作用。

有谁知道我如何实现这一目标?

0 投票
1 回答
466 浏览

cocoa - NSSegmentedControl 用户默认值中的选定段

在用户默认值中存储分段控件的 selectedSegment 时出现问题。我正在使用 Segment Selection 绑定并这样做来设置和调用默认值:

不工作。有人可以帮我吗?

-谢谢

保罗。

0 投票
0 回答
752 浏览

objective-c - NSSegmentedCell Subclass and Custom Geometry/Layout Impossible?

A Tale of Two Subclasses

By Ben Stock

Prologue

I'm in the process of making a really nice looking set of controls which automatically change their appearance depending on the type of window they're used in (e.g. If you drop a button in a normal window, it looks like any other standard Aqua button. If you drop it on an NSPanel with a window mask of NSHUDWindowMask, however, it'll automatically switch its style to look good on a HUD background. So far, I've subclassed NSButton, NSTextField, NSSlider, and NSSearchField. Last night I started on NSTabView, only to be slammed down by its lack of customizability. It's a real pain in the ass, but I'm a developer, so I'm used to finding my own way. The first thing I think to do is add an instance of NSSegmentedControl in place of the private tabs used by NSTabView. So far, so good. I've got the buttons selectable, they automatically update when new NSTabViewItem's are added, and they work just like the real thing.

And the Pain Begins …</h2>

Finally, I start to style my segments, and … WTF have I gotten myself into‽ I should've just gone into acting or something. Objective-C development is slowly taking years off my life. No matter what I do, the "tracking areas" used by NSSegmentedCell don't seem to be updating when my segment widths change. So when my widths change, my artwork does, too. However, the actual tracking area doesn't update (even when I override -updateTrackingAreas. It's really hard to explain, so I decided to draw my segment rectangles behind and in front of the ones drawn by super in -drawSegment:inFrame:withView. Here's a screenshot with my art drawn on top of the underlying tracking areas:

A HUD Panel in Mac OS X displaying debug rectangles.

And here's super's implementation above my segment rects:

enter image description here

I've tried overriding everything I can think of. Here are a few of the methods I've overridden (and un-overridden):

  • -cellSize (NSSegmentedCell)
  • -cellSizeForBounds: (NSSegmentedCell)
  • -sizeToFit (NSSegmentedControl)
  • -intrinsicContentSize (NSSegmentedControl)
  • -setWidth:forSegment: (NSSegmentedControl/Cell)
  • -startTrackingAt:inView: (NSSegmentedCell)
  • -continueTracking:at:inView: (NSSegmentedCell)
  • -stopTracking:at:inView:mouseIsUp: (NSSegmentedCell)

At this point, some of those methods in the above list are still using my overrides and some aren't. I've mixed and matched, deleted, simplified, rewrote, and refactored, and no matter what I do, the underlying rectangles don't change. I love Apple as much as the next guy, but their view of customization needs to change. I can't stand not being able to understand what's going on in the implementation of all these stupid controls. Not to mention the fact that I still can't fully wrap my head around Auto Layout (which is about the most un-"auto" thing I've ever dealt with), but that's a post for another day. Anyway, if anybody could help a brotha out, I'd be super grateful. Sorry for ranting and thanks for reading!

P.S. None of these things are finished, so please don't be too hard on a few pixel imperfections. ;-)