简体   繁体   English

NSTextView圆角和绘制背景

[英]NSTextView round corners and draw background

For two I've been working on following problem: 对于两个我一直在努力解决以下问题:

I'm supposed to create message chat view which is going to be placed in NSTableView . 我应该创建消息聊天视图,它将放在NSTableView It has to have color background, rounded corners, custom margins. 它必须有彩色背景,圆角,自定义边距。 I tried with NSTextField but with no success. 我试过NSTextField但没有成功。 I have desired background and rounded corners but text is not displayed correctly because it starts in the center of the field in case of multiline. 我有所需的背景和圆角,但文字显示不正确,因为它在多行的情况下从字段的中心开始。 Also I tried with NSTextView , which seems to be better solution in this situation, but I couldn't set rounded corners. 此外,我尝试使用NSTextView ,这似乎是在这种情况下更好的解决方案,但我无法设置圆角。 I tried using [textView.layer setCornerRadius:7.0]; 我尝试使用[textView.layer setCornerRadius:7.0]; but it gives no effect. 但它没有任何效果。

Thanks for any reply! 谢谢你的回复!

Add it to Text View property 将其添加到“文本视图”属性

在此输入图像描述

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

And you can see> 你可以看到>

在此输入图像描述

But you Scroll View backgroundColor should be WindowBackgroundcolor 但你滚动视图backgroundColor应该是WindowBackgroundcolor

在此输入图像描述

在此输入图像描述

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

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