macOS 10.12.4 NSButton After adding CAGradientLayer, button title is not displayed

71 views Asked by At

The purpose of the following code is to achieve a gradient background color In newer versions, it looks fine, but in macOS 10.12.4, the title of the button doesn't appear

- (void)setGradient:(NSArray<__kindof NSColor *> *)colorArr StartPoint:(CGPoint)startPoint EndPoint:(CGPoint)endPoint {
    self.wantsLayer = YES;
    CAGradientLayer *gradinentlayer = [CAGradientLayer layer];
    NSMutableArray *array = [NSMutableArray array];
    for (NSColor *color in colorArr) {
        [array addObject:(id)color.CGColor];
    }
    gradinentlayer.colors = array;
    gradinentlayer.startPoint = startPoint;
    gradinentlayer.endPoint = endPoint;
    gradinentlayer.frame = self.bounds;
    [self.layer insertSublayer:gradinentlayer atIndex:0];
}

How do I make the title text appear, other than adding a subview?

Any help would be appreciated!

I've tried :

self.layer = gradinentlayer;

But this invalidates the layer's other Settings,This is not in line with expectations

0

There are 0 answers