2013-10-22 130 views
0

如何設置NSButton背景圖片?如何設置NSButton背景圖片

[_myButton setImage:[NSImage imageNamed:@"foo.png"]];

這隻會改變圖像圖標按鈕,但沒什麼選項了setBackgroundImage爲UIButton

+0

可能重複(http://stackoverflow.com/questions/4608454/setting-a-background- image-for-uibutton) – emreoktem

+5

@emreoktem - NSButton不是UIButton – Abizern

回答

1

嘗試這樣的: - [設置的背景圖像的UIButton]的

NSString* img = [[NSBundle mainBundle] pathForResource:@"Your Image" ofType:@"png"]; 
NSURL* url = [NSURL fileURLWithPath:img ]; 
NSImage *image = [[NSImage alloc] initWithContentsOfURL: url]; 
[yourButton setImage: image] ; 
4
[_myButton setImage:[NSImage imageNamed:@"foo.png"]]; 
[_myButton setBordered:NO]; 
[_myButton sizeToFit];