1

我在这里按照答案:

https://stackoverflow.com/a/3233802/3850487

我能够使用@Dave 代码并且效果很好。

唯一的问题是我似乎找不到更改标签字体或大小的方法。

[self.rssLabel setText:fullString];
[self.rssLabel setSpeed:0.03f];
[[self rssLabel] setFont:[NSFont boldSystemFontOfSize:100]];//NOT WORKING

什么都没有发生,就像没有受到影响一样。

我得到的最接近的是当我添加一些代码时- (void)drawRect:(NSRect)dirtyRect

- (void)drawRect:(NSRect)dirtyRect {
    // Drawing code here.  
    [[NSColor grayColor] set];//changed the background of the view 
    NSRectFill(dirtyRect);    //not text color
    ...

}

我试图联系戴夫,但我还不能发表评论,请指教。

4

1 回答 1

0

没错,您需要在drawRect:(NSRect)dirtyRect.

例子:

- (void)drawRect:(NSRect)dirtyRect {
    // Drawing code here.
    NSFont *font = [NSFont fontWithName:@"Courier" size: 15.0f];
    //add more custom stuff, then assign attributes
    NSDictionary *attributes = @{ NSFontAttributeName: font};

    if (point.x + stringWidth < 0) {
        point.x += dirtyRect.size.width;
    }

    [text drawAtPoint:point withAttributes:attributes];//assign!

    if (point.x < 0) {
        NSPoint otherPoint = point;
        otherPoint.x += dirtyRect.size.width;
        [text drawAtPoint:otherPoint withAttributes:attributes];//assign!
    }
}
于 2014-09-30T16:58:01.510 回答