15. 点击查看helloView.h文件,发现文件被自动修改了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // // helloView.m // helloworld // // Created by Jianhong Ou on 2/23/10. // Copyright 2010 University of Massachusetts. All rights reserved. // #import "helloView.h" @implementation helloView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code here. } return self; } - (void)drawRect:(NSRect)dirtyRect { // Drawing code here. } @end |
16. 修改helloView.h文件为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // // helloView.m // helloworld // // Created by Jianhong Ou on 2/23/10. // Copyright 2010 University of Massachusetts. All rights reserved. // #import "helloView.h" @implementation helloView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code here. } return self; } - (void)drawRect:(NSRect)dirtyRect { // Drawing code here. NSString* hello = @"Hello, World!"; NSPoint point = NSMakePoint(15, 75); NSMutableDictionary* font_attributes = [NSMutableDictionary new]; NSFont* font = [NSFont fontWithName:@"Futura-MediumItalic" size:42]; [font_attributes setObject:font forKey:NSFontAttributeName]; [hello drawAtPoint:point withAttributes:font_attributes]; [font_attributes release]; } @end |
注意到Objective-C的语法奇怪的地方,方括号:[对象 动作1:动作1参数 动作2:动作2参数 ...];
注意到字符以@起始:@”字符内容”
转载请注明文章来自糗世界博客
«上一篇 月晕而风 | 新概念英语补充词汇 下一篇»Tags: cocoa application, objective c, xcode, 教程, 程序, 编程

