簡體   English   中英

我如何在iPhone應用程序中集成股票行情

[英]how can i integrate ticker in iphone application

我想用ticker運行基於視圖的窗口應用程序。我有代碼的代碼,但是它在可可中..所以我如何將可可應用程序集成到我的項目中呢?

這是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

就我所知,您不能只是將其放入。

我可以通過將您的繼承從NSTextView更改為UILabel並閱讀文檔來實現。 然后只需一點一點地處理代碼,直到它起作用;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM