有没有办法自定义NSPopUpButton箭头的颜色?我环顾了四周,但还没有找到答案
发布于 2012-06-02 03:14:12
我真的不认为有一个“简单”的方法来做到这一点。如果你看一下API描述,它甚至声明它不响应setImage例程。我已经做了相当多的工作,按钮对象的子类化,等等。我认为这是你必须去做的地方,以完成你所要求的。
发布于 2015-02-27 07:21:40
像许多这样的控件一样,我是通过继承NSPopupButton(单元格),然后在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];
}发布于 2017-11-27 19:20:05
我这样做了,它对我很有效。
(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.
}https://stackoverflow.com/questions/10855915
复制相似问题