NSOutlineView是Cocoa的树形控件,这里介绍如何快速修改NSOutlineView系统的箭头样式,随意改成产品给你的箭头样式。
1、系统的箭头样式:
2、修改后的箭头样式
3、代码:
新建一个NSOutlineView的子类,我命名为MyOutlineView,在MyOutlineView.m方法里,重写- (id)makeViewWithIdentifier:(NSString *)identifier owner:(id)owner方法如下:
- (id)makeViewWithIdentifier:(NSString *)identifier owner:(id)owner
{
id view = [super makeViewWithIdentifier:identifier owner:owner];
if ([identifier isEqualToString:NSOutlineViewDisclosureButtonKey])
{
// Do your customization
// return disclosure button view
[view setImage:[NSImage imageNamed:@"右拉-改"]];
[view setAlternateImage:[NSImage imageNamed:@"下拉-改"]];
[view setBordered:NO];
[view setTitle:@""];
return view;
}
return view;
}
4、关联:
把你原来的NSOutlineView类对象设置为MyOutlineView类对象,如下所示: