【问题标题】:How to apply tint color to NSButton (style Inline) cocoa如何将色调颜色应用于 NSButton(内联样式)可可
【发布时间】:2019-11-09 08:03:04
【问题描述】:

如何将色调颜色应用于样式inline 和视觉bordered 的NSButton 下面是我正在使用的代码块

第一轮是内联按钮

使用以下代码后

InlineButton.wantsLayer = YES;
        InlineButton.layer.backgroundColor = [NSColor redColor].CGColor;

如何只改变按钮的色调

任何建议都会更有帮助。

【问题讨论】:

    标签: macos cocoa nsbutton tint


    【解决方案1】:

    按钮的isBordered属性与bezelStyle属性相关。您可以设置不同的样式来检查外观。

    如果您希望按钮图像具有特定颜色。尝试使用模板图像和contentTintColor

    let button = NSButton()
    button.image = NSImage(named: NSImage.stopProgressFreestandingTemplateName)
    button.image?.isTemplate = true
    button.bezelStyle = .inline
    button.isBordered = false
    button.contentTintColor = NSColor.red
    

    【讨论】:

      【解决方案2】:

      示例(斯威夫特):

      /// The system window mockup
      var layer = self.systemWindowMockupView.layer
      layer?.cornerRadius = 6
      layer?.backgroundColor = settings.windowBackgroundColor?.cgColor
      layer?.masksToBounds = true. // <<<---- This is what you're looking for
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-23
        • 2011-05-23
        • 2015-01-11
        • 1970-01-01
        • 2018-01-29
        相关资源
        最近更新 更多