如何更改NSOutlineView DisclosureButt
2019-01-06 本文已影响0人
LyleWh
NSOutlineView默认的DisclosureButton是在左边,如下图所示:
屏幕快照 2019-01-06 下午7.20.35.png
屏幕快照 2019-01-06 下午7.22.42.png
现在需要将其更改为在右边,并将其图片更改:
屏幕快照 2019-01-06 下午7.22.42.png
实现方法如下
1 自定义NSOutlineView
@interface LYOutlineView : NSOutlineView
@end
2 重写- (void)layout方法
[super layout];
for (NSView *view in self.subviews) {
for (NSView *subView in view.subviews) {
if ([subView.identifier isEqualToString:NSOutlineViewDisclosureButtonKey]) {
// 设置图片
NSButton *disclosure = (NSButton *)subView;
disclosure.imageScaling = NSImageScaleProportionallyUpOrDown;
disclosure.image = [NSImage imageNamed:@"jiantouyou"];
disclosure.alternateImage = [NSImage imageNamed:@"jiantouxia"];
// 设置frame
CGFloat x = view.frame.size.width - 100;
CGFloat y = disclosure.frame.origin.y;
[disclosure setFrameOrigin:NSMakePoint(x, y)];
}
}
}