e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 操作系统 >> 苹果OS教程 >> Mac OS X教程-技巧-MAC OS X Cocoa NSToolbar 的使用 >> 教程正文
 
教程搜索
 
 
相关教程
  • 4月29日:我们将看到新的苹果OS:Tige
  • MacTracker苹果机型数据库
  • Tiger技术预览大会
  • MacOSX: 命令行启动default browser,
  • 看来Safari用 cu blog 不是特别爽哟。
  • Microsoft 的 Entourage
  • Mac OS X上开关机时的小技巧
  • FireWire 技术
  • 转载:用VMWARE 3.0安装LINUX 的一点心
  • Mac OS X教程-技巧-Windows装上MacOS 
  • Mac OS X教程-技巧-Macintosh的101个应
  • Mac OS X教程-技巧-Macintosh的101个应
  • Mac OS X教程-技巧-Macintosh的101个应
  • Mac OS X教程-技巧-Macintosh的101个应
  • Mac OS X教程-技巧-Macintosh的101个应
  • Mac OS X教程-技巧-Macintosh的101个应
 
 

图文教程


  • Windows抢了谁的饭碗 非主流操作系统To

  • 地球还是火星 平常心看“非主流”

  • 综合运用Office 2007批量制作奖状

  • 没有系统盘如何才能修复受损系统?

  • 巧妙运用Excel中边界的附加功能!
 
 
赞 助 商
 
 
Mac OS X教程-技巧-MAC OS X Cocoa NSToolbar 的使用
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9

//向NSToolbar控件添加自定义的NSToolbarItem项

- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:

(NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {

// Required delegate method Given an item identifier, self method

returns an item

// The toolbar will use self method to obtain toolbar items that can

be displayed in the customization sheet, or in the toolbar itself

NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc]

initWithItemIdentifier: itemIdent] autorelease];

if ([itemIdent isEqual: SquareDotViewItemIdentifier]) {

SquareDotView *dv = [[SquareDotView alloc] initWithFrame:

NSMakeRect(0,0,100,32)];

[toolbarItem setView: dv];

// set a reasonable minimum size

[toolbarItem setMinSize: NSMakeSize(100,32)];

// set a maximum size that allows us to stretch.

[toolbarItem setMaxSize: NSMakeSize(300,32)];

[toolbarItem setLabel: @"Dot View"];

[toolbarItem setPaletteLabel: @"A Dot View"];

[toolbarItem setToolTip: @"This is a dot view"];

}

.....

}

//返回单击后能被选中且为高亮显示的NSToolbarItem的集合。

- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar

{// return an array of all the items that can be highlight display after selected

return [NSArray arrayWithObjects:

NSColorToolbarItemIdentifier,


NSFontToolbarItemIdentifier,nil];

}

//返回程序加载后的默认的NSToolbarItem的集合。

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar

{ // return an array of the items found in the default toolbar

return [NSArray arrayWithObjects:

NSToolbarSeparatorItemIdentifier,

NSFontToolbarItemIdentifier,

NSToolbarCustomizeToolbarItemIdentifier,

nil];

}

//以下是作为NSToolbarItem出现的自定义类

The "SquareDotView" class:

@interface SquareDotView : NSView {

@private

float sdSide;

NSPoint sdLocation;

}

@end

@implementation SquareDotView

#define START_SIDE 10

#define START_LOCATION NSMakePoint(10,10)

- (id)initWithFrame:(NSRect)frame {

self = [super initWithFrame:frame];

if (self) {

sdSide = START_SIDE;

sdLocation = START_LOCATION;

}

return self;

}

- (void)mouseDown:(NSEvent *)theEvent {

sdLocation = [self convertPoint: [theEvent locationInWindow]

fromView: nil];

[self setNeedsDisplay: YES];

}

- (void)drawRect:(NSRect)rect {

[[NSColor redColor] set];

[[NSBezierPath bezierPathWithRect: NSMakeRect(sdLocation.x,

sdLocation.y, sdSide, sdSide)] fill];

[[NSColor blackColor] set];

[[NSBezierPath bezierPathWithRect: [self bounds]] stroke];

}

- (id)initWithCoder:(NSCoder *)coder {

self = [super initWithCoder: coder];

if (self) {

[coder decodeValuesOfObjCTypes: "fff", &sdSide, &sdLocation.x,

&sdLocation.y];

}

return self;

}

- (void)encodeWithCoder:(NSCoder *)coder {

[super encodeWithCoder: coder];

if (self) {

[coder encodeValuesOfObjCTypes: "fff", &sdSide, &sdLocation.x,

&sdLocation.y];

}

}

@end


  • 上一篇教程: Mac OS X教程-技巧-MAC OS X 中的终端程序
  • 下一篇教程: Mac OS X教程-技巧-Macintosh的101个应用技巧(6)
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.