2010-07-08 45 views
1

我想运行我的基于视图的窗口应用程序与ticker.i有股票代码,但它是在可可..所以我怎么可以整合可可应用程序在我的项目。我怎样才能整合iPhone应用程序中的代码

这是TickerView.h文件

#import <Cocoa/Cocoa.h> 


@interface TickerView : NSTextView { 
@private 
    NSTimer  *mTimer; 
    double  mOffset; 
} 
- (NSString *)stringValue; 
- (void)setStringValue:(NSString *)stringValue; 

- (void)appendString:(NSString *)s; 

- (IBAction)startAnimation:(id)sender; 
- (IBAction)stopAnimation:(id)sender; 

@end 

这是TickerView.m文件

#import "TickerView.h" 


@implementation TickerView 

- (id)initWithFrame:(NSRect)frame { 
    self = [super initWithFrame:frame]; 
    if (self) { 
    [self setEditable:NO]; 
    NSTextContainer *container = [self textContainer]; 
    [container setWidthTracksTextView:NO]; 
    [container setContainerSize:NSMakeSize(99999., frame.size.height)]; 
    } 
    return self; 
} 

- (void)dealloc { 
    [self stopAnimation:self]; 
    [super dealloc]; 
} 

- (void)drawRect:(NSRect)rect { 
    [super drawRect:rect]; 
} 

- (NSString *)stringValue { 
    return [[self textStorage] string]; 
} 

- (NSDictionary *)standardAttributes { 
    return [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSFont fontWithName:@"Helvetica" size:([self frame].size.height * 0.8)], NSFontAttributeName, 
    [NSColor redColor], NSForegroundColorAttributeName, 
    nil]; 
} 

- (void)setStringValue:(NSString *)s { 
    NSRange fullRange = NSMakeRange(0, [[self textStorage] length]); 
    NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease]; 
    [[self textStorage] replaceCharactersInRange:fullRange withAttributedString:sa]; 
} 

- (void)appendString:(NSString *)s { 
    NSRange endRange = NSMakeRange([[self textStorage] length], 0); 
    NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease]; 
    [[self textStorage] replaceCharactersInRange:endRange withAttributedString:sa]; 
} 


- (IBAction)startAnimation:(id)sender { 
    if (nil == mTimer) { 
    mTimer = [NSTimer scheduledTimerWithTimeInterval:1./60. target:self selector:@selector(step:) userInfo:nil repeats:YES]; 
    } 
} 


- (IBAction)stopAnimation:(id)sender { 
    if (mTimer) { 
    [mTimer invalidate]; 
    [mTimer release]; 
    mTimer = nil; 
    } 
} 

- (void)step:(NSTimer *)timer { 
    mOffset -= 2; // pixels per tick 
    [self setTextContainerInset:NSMakeSize(mOffset, 0)]; 
    [self setNeedsDisplay:YES]; 
} 


@end 

回答

0

你不能仅仅将它放在(据我所知)。

我会通过改变你从NSTextView到UILabel的继承来完成它,并阅读the docs。然后只是通过代码一点点工作,直到它的工作;)

+0

感谢您的suggetion .. 但它仍然无法正常工作。 – Pradeep 2010-07-08 14:07:28

+0

需要更多的信息,而不是'不工作';) - 如果你编辑你的问题,你可以添加更多的细节。 – deanWombourne 2010-07-08 14:09:42

+0

我做了我的代码更改,因为你说...但它仍然给我下面的错误..我是新的iPhone应用程序编程.. 'NSTextContainer'未申报(首次使用此功能) '容器'未申报在一次使用此功能) “字体”未声明(先入该函数使用) “NSFontAttributeName”未声明(在一次使用此功能) /“文字颜色”未声明(在一次使用此功能) ' NSForegroundColorAttributeName'未申报(首次使用此功能) 请指导我 – Pradeep 2010-07-09 08:16:54

相关问题