如何为“过冲"着色NSCollectionView 的背景 [英] How to Color the "Overshoot" Background of an NSCollectionView

查看:25
本文介绍了如何为“过冲"着色NSCollectionView 的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照

我正在尝试将整个内容区域设为黑色.在我的故事板中,我将包含集合视图的 NSScrollViewNSClipView 的背景颜色设置为黑色,但它不会改变外观.还尝试了编程替代方案:为滚动视图设置一个插座并调用:

self.scrollview.backgroundColor = NSColor.blackself.scrollview.contentView.backgroundColor = NSColor.black

...没有效果.

另外,我试过:

collectionView.superview?.layer?.backgroundColor = NSColor.black.cgColor

...但这也不起作用.

也没有:

self.view.layer?.backgroundColor = NSColor.black.cgColor

或:

self.view.window?.backgroundColor = NSColor.black

<小时>

更新:

我已将滚动视图的背景颜色设置为红色,并将 drawsBackground 设置为 true(在 IB 中和以编程方式).NSScrollViewbackgroundColor 属性的文档说:

<块引用>

此颜色用于绘制内容视图内不属于被文档视图覆盖.

我已经在运行时验证文档视图确实是我的集合视图:

如果 scrollview.documentView 是 NSCollectionView {print("文档是集合")}

但是,没有显示红色,文档以外的区域(集合视图)保持白色.

<小时>

更新 2: 我启动了 View Hierarchy Debugger,看起来 drawsBackground 的值在运行时为 false(我将它设置为 true两者代码故事板)!:

(不过,背景颜色本身似乎被反射了)

解决方案

  1. 在 Interface Builder 中,选择文档大纲中的 CollectionView.
  2. 在实用工具"窗口中,显示属性"检查器.
  3. 在主颜色选择器控件中设置所需的颜色.

注意:您引用的 Ray Wenderlich 教程以编程方式设置了集合视图的背景颜色.您要么想要删除那条线,要么确保您设置的颜色与您在上述第 3 步中选择的颜色相同.

I have implemented a collection view on my Cocoa app following Ray Wenderlich's tutorial (very helpful, given how buggy and broken Apple's API is in this area).

In the tutorial, the collection view's canvas is colored black using the following code (all code is in view controller class' viewDidLoad() method):

collectionView.layer?.backgroundColor = NSColor.black.cgColor

However, the area that "peeks" when you overshoot ("rubber-band") the scroll using -for example- a magic mouse/scrollwheel, is still white and very distracting:

I'm trying to make the whole content area black. In my storyboard, I set the background color of both the NSScrollView and NSClipView that contain the collection view to black, but it doesn't change the appearance. Also tried the programmatic alternative: setup an outlet for the scrollview and call:

self.scrollview.backgroundColor = NSColor.black
self.scrollview.contentView.backgroundColor = NSColor.black

...to no effect.

Additionally, I tried:

collectionView.superview?.layer?.backgroundColor = NSColor.black.cgColor

...but this doesn't work either.

Neither does:

self.view.layer?.backgroundColor = NSColor.black.cgColor

or:

self.view.window?.backgroundColor = NSColor.black


Update:

I have set the background color of the scroll view to red, and drawsBackground to true (both in IB and programmatically). The docs for NSScrollView's backgroundColor property say:

This color is used to paint areas inside the content view that aren’t covered by the document view.

I have verified at runtime that the document view is indeed my collection view:

if scrollview.documentView is NSCollectionView {
        print("Document is collection")
}

However, no red is displayed and the area beyond the document (collection view) stays white.


Update 2: I fired the View Hierarchy Debugger, and it seems that the value of drawsBackground is false at runtime (I set it to true in both code and storyboard)!:

(the background color itself seems to be reflected, though)

解决方案

  1. In Interface Builder, select the CollectionView in the document outline.
  2. In the Utilities window, show the Attributes inspector.
  3. Set the desired color in the Primary color selector control.

Note: the Ray Wenderlich tutorial that you referenced sets the background color of the collection view programmatically. You'll either want to remove that line, or ensure that you are setting the same color that you chose in step 3 above.

这篇关于如何为“过冲"着色NSCollectionView 的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆