1
ticker.i로 내보기 기반 창 응용 프로그램을 실행하고 싶습니다. 티커 용 코드가 있지만 코코아에 있습니다. 내 프로젝트에서 코코아 응용 프로그램을 어떻게 통합 할 수 있습니까?어떻게 iphone 응용 프로그램에서 티커를 통합 할 수 있습니다
이 (내가 아는까지로)
#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
suggetion을 주셔서 감사합니다. 그러나 여전히 작동하지 않습니다. – Pradeep
'작동하지 않는 것'보다 자세한 정보가 필요합니다;) - 질문을 편집하는 경우 자세한 내용을 추가 할 수 있습니다. – deanWombourne
내가 말한대로 내 코드를 변경 했는데도 계속 오류가 발생합니다 .iphone 응용 프로그램 프로그래밍에 익숙하지 않습니다. 'NSTextContainer'가 선언되지 않았습니다 (이 함수에서 처음 사용) '컨테이너'가 선언되지 않았습니다. 이 기능의 제 사용) '폰트'미표시 (제 1)이 기능에서 사용 'NSFontAttributeName'미표시 (제 1)이 기능에서 사용 /'텍스트 색상'미표시 (제 1)이 기능에서 사용 ' NSForegroundColorAttributeName '이 선언되지 않음 (이 함수에서 처음 사용) 나를 안내하십시오 – Pradeep