1

表示したいウィンドウがあり、10.11 では期待どおりに表示されます。

でウィンドウ内のビューのすべてのプロパティを設定します-windowDidLoad。ウィンドウが表示されると、これらのボタンは適切な色になります。

ここに画像の説明を入力

- (void)windowDidLoad
{
   [super windowDidLoad];

   LightTheme *lightTheme = [[LightTheme alloc] init];

   _cancelButton.backgroundColor = lightTheme.controlColor;
   _stopButton.backgroundColor = lightTheme.controlColor;
   _cancelButton.textColor = lightTheme.textColor;
   _stopButton.textColor = lightTheme.textColor;
}

ただし、10.10 の同じコードでは、色はこのボタン サブクラスのデフォルト値に設定されます。

ここに画像の説明を入力

興味深いのは、ボタンを操作すると、すぐに再描画され、適切な白い背景になることです。

ただし、コードを -awakeFromNib に移動すると、ウィンドウが表示されるとすぐに、両方の OS で適切に表示されます。

- (void)awakeFromNib
{
   [super awakeFromNib];

   LightTheme *lightTheme = [[LightTheme alloc] init];

   _cancelButton.backgroundColor = lightTheme.controlColor;
   _stopButton.backgroundColor = lightTheme.controlColor;
   _cancelButton.textColor = lightTheme.textColor;
   _stopButton.textColor = lightTheme.textColor;
}

10.10→10.11でウィンドウ表示時の表示が変わった?それとも、他に何か不足していますか?

以前は次のようでした。

-awakeFromNib -> 表示ウィンドウ

次のようになります。

-windowDidLoad -> 表示ウィンドウ

編集:backgroundColorプロパティの使用方法は次のとおりです:
まず、ボタンの状態に応じて色を取得します。

-(NSColor*)effectiveBackgroundColor
{   
   NSColor *result = ([self isOn] && self.backgroundAlternateColor) ? self.backgroundAlternateColor : self.backgroundColor;

   if ( !self.enabled && result ) // if disabled, dim the background
      result = [result colorWithAlphaComponent:self.disabledOpacity];

   return result;
}

次に、 で次の-drawRectメソッドを呼び出します。

-(void)drawBackground
{
   NSSize inset = [self buttonInset];

   NSRect bodyRect = self.bounds;
   bodyRect = NSInsetRect(bodyRect, inset.width, inset.height);

   NSBezierPath* buttonPath = [NSBezierPath bezierPathWithRoundedRect:bodyRect xRadius:self.cornerRadius yRadius:self.cornerRadius];
   NSColor* effectiveBackgroundColor = [self effectiveBackgroundColor];

   if (effectiveBackgroundColor)
   {
      [NSGraphicsContext saveGraphicsState];
      [[self effectiveBackgroundShadow] set];
      [effectiveBackgroundColor setFill];
      [buttonPath fill];
      [NSGraphicsContext restoreGraphicsState];

      if( [[self cell] isHighlighted] )
      {
         [[[NSColor blackColor] colorWithAlphaComponent:self.highlightOpacity] setFill];
         [buttonPath fill];
      }
   }
}
4

0 に答える 0