2010-07-08 3 views
1

Я хочу запустить мое оконное приложение, основанное на представлении, с тикером. У меня есть код для тикера, но он находится в какао. так как я могу интегрировать приложение какао в свой проект?Как я могу интегрировать тикер в приложении 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

спасибо за ваше предложение .. , но он все еще не работает. – Pradeep

+0

Потребуется больше информации, чем «не работает»;) - если вы отредактируете свой вопрос, вы можете добавить более подробную информацию. – deanWombourne

+0

Я внес изменения в свой код в соответствии с u сказал .. но он по-прежнему дает мне следующую ошибку. Я новичок в программировании приложений iphone. «NSTextContainer» uneclared (первое использование в этой функции) «контейнер» необъявленный (первое использование в этой функции) «шрифта» недекларируемый (сначала использовать в этой функции) «NSFontAttributeName» необъявленный (первое использование в этой функции) /«TextColor» необъявленный (первое использование в этой функции) ' NSForegroundColorAttributeName 'uneclared (сначала использовать в этой функции) , пожалуйста, назовите меня – Pradeep