// // KMPopMenuButtonCell.m // SignFlow // // Created by 丁林圭 on 2021/9/3. // #import "KMPopMenuButtonCell.h" @implementation KMPopMenuButtonCell - (NSRect)titleRectForBounds:(NSRect)rect { CGRect rect1 = [super titleRectForBounds:rect]; return CGRectMake(21 + 5 + self.image.size.width, rect1.origin.y, self.attributedTitle.size.width, self.attributedTitle.size.height); } - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView { if (![self isEnabled]) { NSColor *txtColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.8]; if (@available(macOS 10.14, *)) { NSAppearanceName appearanceName = [[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; if ([appearanceName isEqualToString:NSAppearanceNameDarkAqua]) { txtColor = [NSColor colorWithWhite:1.0 alpha:0.5]; NSMutableAttributedString *myAttr = [[NSMutableAttributedString alloc] initWithAttributedString:title]; [myAttr addAttribute:NSForegroundColorAttributeName value:txtColor range:NSMakeRange(0, myAttr.length)]; return [super drawTitle:myAttr withFrame:frame inView:controlView]; } } } return [super drawTitle:title withFrame:frame inView:controlView]; } - (NSRect)imageRectForBounds:(NSRect)rect { if (self.image) { CGRect imageRect = [super imageRectForBounds:rect]; return CGRectMake(21, imageRect.origin.y, imageRect.size.width, imageRect.size.height); } return CGRectZero; } @end