5
如何將圖像設置爲觸控板上的按鈕(用於新MacBook Pro)? 我嘗試了下面的代碼,但它不起作用,如果我運行下面的代碼,沒有按鈕出現在觸摸欄中。Xcode:將圖像設置爲觸控板上的按鈕(適用於新MacBook Pro)
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
if ([identifier isEqualToString:TouchBarMacScanIdentifier])
{
NSButton* theButton = [NSButton buttonWithTitle:@"Scan" target:self action:@selector(clickFullScan:)];
[theButton setImage:[NSImage imageNamed:@「scan.png」]];
[theButton setImagePosition:NSImageLeft];
NSCustomTouchBarItem *customItemForButton =
[[NSCustomTouchBarItem alloc] initWithIdentifier:TouchBarMacScanIdentifier];
customItemForButton.view = theButton;
customItemForButton.visibilityPriority = NSTouchBarItemPriorityLow;
return customItemForButton;
}
...
return nil;
}
如果我註釋掉以下兩行,我可以看到觸摸欄中顯示的按鈕。
[theButton setImage:[NSImage imageNamed:@「scan.png」]];
[theButton setImagePosition:NSImageLeft];
那麼,怎麼了?如何將圖像設置爲觸摸欄上的按鈕?