2012-06-01 145 views

回答

1

我真的不认为有一个“简单”的方法来做到这一点。如果你看看API描述,它甚至会说它不响应setImage例程。我已经完成了很多按子对象分类的工作,等等......我认为这是你为了做你所要求的而必须去的地方。

0

像太多这些控件一样,我通过继承NSPopupButton(Cell),然后在drawRect中完成所有自己的绘图操作...我尽管做了一些欺骗操作,并且使用图像做了实际的三角形,而不是尝试通过基元来完成。

- (void)drawRect:(NSRect)dirtyRect 
{ 
    //...Insert button draw code here... 
    //Admittedly the above statement includes more work than we probably want to do. 
    //Assumes triangleIcon is a cached NSImage...I also make assumptions about location 

    CGFloat iconSize = 6.0; 
    CGFloat iconYLoc = (dirtyRect.size.height - iconSize)/2.0; 
    CGFloat iconXLoc = (dirtyRect.size.width - (iconSize + 8)); 

    CGRect triRect = {iconXLoc, iconYLoc, iconSize, iconSize}; 
    [triangleIcon drawInRect:triRect]; 
} 
0

我做到了这一点,它为我工作。

(void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
    NSPopUpButton *temp = (NSPopUpButton*)controlView; 

    NSString *strtile = temp.title; 

    AppDelegate *appdel = (AppDelegate*)[NSApplication sharedApplication].delegate; 
    NSFont *font = [NSFont systemFontOfSize:13.5]; 
    NSSize size = NSMakeSize(40, 10);// string size 

    CGRect rect = controlView.frame; 
    rect = CGRectMake((size.width + temp.frame.size.width)/2, rect.origin.y, 8, 17); 

    [self drawImage:[NSImage imageNamed:@"icon_downArrow_white.png"] withFrame:rect inView:self. 
}