MAC OS X Cocoa NSToolbar 的使用

//向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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Mac OS上的UI测试框架有以下几种: 1. XCTest:苹果公司自带的测试框架,是Mac OS的默认测试工具,功能强大且易于使用。 2. Appium:跨平台的开源测试框架,支持Mac OS,可以用于测试苹果移动应用和桌面应用。 3. Calabash:开源的移动应用测试框架,支持苹果移动应用,可以进行自动化测试。 4. Frank:开源的自动化测试框架,专门用于测试苹果移动应用,可以轻松实现自动化测试。 这些都是常见的Mac OS UI测试框架,可以根据具体需求选择使用。 ### 回答2: Mac OS的UI测试框架有以下几种: 1. XCTest:这是苹果官方提供的用于测试 CocoaCocoa Touch 应用程序的框架。XCTest 框架具有广泛的功能,可以用于编写 UI 测试代码并执行各种测试操作,如模拟用户交互、验证应用程序的行为等。它是开发者常用的 UI 测试框架之一。 2. Appium:这是一个跨平台的开源框架,允许开发者使用多种编程语言(如Python、Java等)编写 UI 测试脚本。Appium 可以用于测试多种移动应用程序,包括 iOS 和 Android。它支持使用 Webdriver 协议进行自动化控制,并提供了丰富的 API 和工具,使测试更加简单和高效。 3. Calabash:这是一个基于 Cucumber 框架的开源测试工具,旨在简化 iOS 应用程序的自动化测试。Calabash 使用 Ruby 语言编写测试脚本,并提供了丰富的 API 和命令行工具来执行测试操作。它支持模拟用户交互、验证应用程序的 UI 元素等功能。 4. KIF(Keep It Functional):这是一个开源的 iOS UI 测试框架,提供了一种简单的方式来编写和执行自动化 UI 测试。KIF 使用 Objective-C 语言编写测试脚本,可以模拟用户操作、查找和验证 UI 元素等。它还提供了丰富的断言和辅助方法,以便开发者能够更方便地验证应用程序的行为。 总之,Mac OS 的 UI 测试框架有许多选择,每个框架都有其独特的特点和适用场景。开发者可以根据具体的需求和技术栈选择合适的框架来进行 UI 测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值