【发布时间】:2017-07-22 16:12:32
【问题描述】:
我想创建一个带有属性字符串的简单标签。我这样做:
NSDictionary *noNotificationsAttrs = [NSDictionary dictionaryWithObjectsAndKeys:centredStyle,
NSParagraphStyleAttributeName,
[NSFont fontWithName:@"Raleway-Bold" size:30],
NSFontAttributeName,
_grey,
NSForegroundColorAttributeName,
nil];
NSMutableAttributedString *noNotificationsString =
[[NSMutableAttributedString alloc] initWithString:@"No Notifications"
attributes:noNotificationsAttrs];
NSTextField* title_field = [[NSTextField alloc] initWithFrame:
CGRectMake(
0,
0,
200,
200
)
];
[title_field setWantsLayer:true];
[title_field setSelectable:YES];
[title_field setAllowsEditingTextAttributes:true];
[title_field setAttributedStringValue:noNotificationsString];
[title_field setEditable:false];
[title_field setBordered:false];
title_field.tag = 1;
结果是这样的:
和
不幸的是,当单击(选择)此标签时,它看起来像这样:
和
这有点大胆和像素化的角落。这发生在许多其他具有不同字符串、大小和颜色的标签上。我该如何解决?!
请注意这些标签嵌套在nsscrollview -> nstableview -> viewForTableColumn
选择堆栈:
我认为问题在于 NSCell 在 mousedown 上调用了一个编辑函数。
编辑:
有趣的是,如果我从 (2) 父视图中删除 wantslayer:YES,它不会这样做。但他们都需要想要的层,否则我不能有弯曲的角落等......
【问题讨论】:
-
您可以通过不将背景设置为
clearColor来修复它。 -
你是最棒的。如果你在我写的另一个问题上回答了我的赏金!确保将其写为答案。
-
不用等待。它没有用......什么?!过了一会儿。
-
啊,它有时会起作用。
-
你在uilabel中启用了用户交互??
标签: objective-c macos nsattributedstring nstextfield