如何在iphone应用程序中集成ticker
我想用ticker运行我的基于视图的窗口应用程序。我有ticker的代码,但它在cocoa中。。 那么,我如何在我的项目中集成cocoa应用程序呢 这是TickerView.h文件如何在iphone应用程序中集成ticker,iphone,objective-c,Iphone,Objective C,我想用ticker运行我的基于视图的窗口应用程序。我有ticker的代码,但它在cocoa中。。 那么,我如何在我的项目中集成cocoa应用程序呢 这是TickerView.h文件 #import <Cocoa/Cocoa.h> @interface TickerView : NSTextView { @private NSTimer *mTimer; double mOffset; } - (NSString *)stringValue; - (vo
#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
(据我所知)你不能随便把它放进去
我可以通过将继承从NSTextView更改为UILabel并读取来实现这一点。然后一点一点地处理代码,直到它工作为止;) 将需要比“不工作”更多的信息;)-如果你编辑你的问题,你可以添加更多的细节。我按照你说的对代码进行了更改。但它仍然给我以下错误。我对iphone应用程序编程还不熟悉NSTextContainer'未声明(此函数首次使用)'container'未声明(此函数首次使用)'font'未声明(此函数首次使用)'NSFontAttributeName'未声明(此函数首次使用)/'textColor'未声明(此函数首次使用)'NSForegroundColorAttributeName'未声明(此函数首次使用)请引导我
#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