【问题标题】:UI issues with custom NSBox自定义 NSBox 的 UI 问题
【发布时间】:2015-02-18 14:12:20
【问题描述】:

我有一个子类 NSBox。在里面我嵌入了一些 NSTextfields,它们在它们的角落显示了一些奇怪的伪影(参见image here)。这是我的 NSBox 子类代码:

    - (void)drawRect:(NSRect)rect {
    NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRoundedRect:rect
                                                                  xRadius: 4
                                                                  yRadius: 4];
    [NSColor whiteColor];
    [rectanglePath fill];
}

有什么想法吗? 谢谢,托马斯

【问题讨论】:

  • 如果要向其中添加 TextFields,为什么要使用 NSBox?过了一点,只使用 NSView 似乎更有意义。
  • stevesliva,我删除了 NSBox 并将其替换为子类 NSView。结果相同。但是当我在 View Effects Inspector 中检查 Core Animation Layer 时,这些绘图问题就消失了。我不明白这里发生了什么。
  • 我会更新您的标题和标签...您可能会通过 Core Animation 查询获得更多响应。
  • Sheen,这没有帮助。文物还在。

标签: objective-c cocoa user-interface nstextfield nsbox


【解决方案1】:

解决问题的方法是使用 [self bounds] 而不是 rect 参数。

- (void)drawRect:(NSRect)rect {
NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRoundedRect:[self bounds]
                                                              xRadius: 4
                                                              yRadius: 4];
[NSColor whiteColor];
[rectanglePath fill];

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多