简体   繁体   English

如何在笔尖上更改NSSplitView的分隔符的颜色?

[英]How to change the color of NSSplitView's divider on nib?

I want to change the color of NSSplitView 's dividerColor in my Cocoa app, but when I typed in the following code, the error Cannot assign to the result of this expression occurred. 我想在我的Cocoa应用程序中更改NSSplitViewdividerColor的颜色,但是当我输入以下代码时,错误Cannot assign to the result of this expression

splitView.dividerColor = NSColor.redColor()

I think this is because .dividerColor is a read-only property and thus you cannot overwrite the color from within code if you instantiate it from nib. 我认为这是因为.dividerColor是一个只读属性,因此如果从nib实例化它,则无法覆盖代码中的颜色。

However, I cannot find any such preferences to change the color in Xcode's Inspector on the NSSplitView . 但是,我找不到任何这样的首选项来更改NSSplitView上Xcode的Inspector中的NSSplitView So how can I change the color of the divider? 那么我怎样才能改变分频器的颜色呢?

Note that I don't use NSSplitViewController ; 请注意,我不使用NSSplitViewController ; I use NSSplitView on top of the NSViewController . 我在NSSplitView之上使用NSViewController

在此输入图像描述

If you're happy to stick to using the Thin Divider style, you can change the color of the splitview's divider by using a subclass of NSSplitView , and overriding the dividerColor property: 如果您乐于坚持使用Thin Divider样式,可以使用NSSplitView的子类更改splitview的分隔符的NSSplitView ,并覆盖dividerColor属性:

class MySplitView: NSSplitView {

    override var dividerColor: NSColor {
        return NSColor.redColor()
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM