自定义NSButton周围的蓝色突出显示

时间:2014-09-23 02:09:44

标签: objective-c cocoa nsbutton

我想为自己的背景制作一个纯色的自定义NSButton,但按钮周围有这个蓝色突出显示,我无法弄清楚如何摆脱它。有谁知道怎么摆脱它?

image of button

谢谢!

编辑:

这里是按钮的代码:

@implementation ZDButton

- (id)init {
    if (self = [super init]) {
        self.title = @"";
        self.isSelected = false;
        [self setBordered:NO];
        [self setBackgroundColor:[NSColor whiteColor]];
    }
    return self;
}


- (void)drawRect:(NSRect)dirtyRect {
   [super drawRect:dirtyRect];

    [[NSColor colorWithCalibratedRed:arc4random_uniform(100) / 100.0
                               green:arc4random_uniform(100) / 100.0
                                blue:arc4random_uniform(100) / 100.0
                               alpha:1.0] set];
    NSRectFill(dirtyRect);

    NSDictionary *att = nil;
    NSMutableParagraphStyle *style =
    [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSLeftTextAlignment];
    att = [[NSDictionary alloc] initWithObjectsAndKeys:
           style, NSParagraphStyleAttributeName,
           [NSColor whiteColor],
           NSForegroundColorAttributeName, nil];

    int width = [self.title sizeWithAttributes:att].width;
    int height = [self.title sizeWithAttributes:att].height;
    int x = (dirtyRect.size.width - width) / 2;
    int y = (dirtyRect.size.height - height) / 2;

    NSRect centeredText = NSRectFromCGRect(CGRectMake(x, y, width, height));
    [self.title drawInRect:centeredText withAttributes:att];

}

@end

0 个答案:

没有答案