NSTextView圆角,绘制背景

问题描述:

两年我一直对以下问题:NSTextView圆角,绘制背景

我应该创造出将要被放置在NSTableView消息聊天视图。它必须有彩色背景,圆角,自定义边距。我试过NSTextField但没有成功。我希望有背景和圆角,但文字显示不正确,因为它在多行的情况下从字段的中心开始。此外,我尝试NSTextView,这似乎是在这种情况下更好的解决方案,但我不能设置圆角。我尝试使用[textView.layer setCornerRadius:7.0];,但它没有效果。

感谢您的回复!

将它添加到文本视图属性

enter image description here

[self.textView setWantsLayer:YES]; 
[self.textView.layer setCornerRadius:10.0f]; 

你可以看到>

enter image description here

但是你滚动视图的backgroundColor应该WindowBackgroundcolor

enter image description here

enter image description here

+0

是啊,它的工作,非常感谢:)其实我做的其他方式,因为,因为我希望它付诸'NSTableView',我不希望它滚动我创建的自定义'NSView'并使其具有圆角并具有背景,然后将Label(它是'NSTextField')放入其中并使其透明。所以这是另一个解决方案,但是非常感谢:) – PawelPawel