KMPopMenuButtonCell.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // KMPopMenuButtonCell.m
  3. // SignFlow
  4. //
  5. // Created by 丁林圭 on 2021/9/3.
  6. //
  7. #import "KMPopMenuButtonCell.h"
  8. @implementation KMPopMenuButtonCell
  9. - (NSRect)titleRectForBounds:(NSRect)rect {
  10. CGRect rect1 = [super titleRectForBounds:rect];
  11. return CGRectMake(21 + 5 + self.image.size.width, rect1.origin.y, self.attributedTitle.size.width, self.attributedTitle.size.height);
  12. }
  13. - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
  14. {
  15. if (![self isEnabled]) {
  16. NSColor *txtColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.8];
  17. if (@available(macOS 10.14, *)) {
  18. NSAppearanceName appearanceName = [[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
  19. if ([appearanceName isEqualToString:NSAppearanceNameDarkAqua]) {
  20. txtColor = [NSColor colorWithWhite:1.0 alpha:0.5];
  21. NSMutableAttributedString *myAttr = [[NSMutableAttributedString alloc] initWithAttributedString:title];
  22. [myAttr addAttribute:NSForegroundColorAttributeName value:txtColor range:NSMakeRange(0, myAttr.length)];
  23. return [super drawTitle:myAttr withFrame:frame inView:controlView];
  24. }
  25. }
  26. }
  27. return [super drawTitle:title withFrame:frame inView:controlView];
  28. }
  29. - (NSRect)imageRectForBounds:(NSRect)rect {
  30. if (self.image) {
  31. CGRect imageRect = [super imageRectForBounds:rect];
  32. return CGRectMake(21, imageRect.origin.y, imageRect.size.width, imageRect.size.height);
  33. }
  34. return CGRectZero;
  35. }
  36. @end