1
A
回答
1
的「北京時間」假設你的意思是水平滾動的文字:
一個股票基本上是由具有其x座標連續改變移動文本字符串。檢查如何顯示在標籤上這個簡單的教程:
http://knol.google.com/k/iphone-sdk-helloworld
後來的後來,你可以通過使用一個NSTimer調用更新標籤X座標連續的方法制作動畫。
+0
否 - 使用UIView類來控制動畫。這些都在Apple文檔中。 – SK9 2010-12-07 07:06:08
5
您需要做的一切都在SDK中,根本不需要自定義。我沒有檢查這一點,但你可以嘗試以下方法:
#import <UIKit/UIKit.h>
@interface TickerScrollView : UIScrollView {
UILabel *textLabel;
}
- (void)displayText:(NSString *)string;
- (void)clearTicker;
@property (nonatomic, retain, readwrite) UILabel *textLabel;
@end
////
#import "TickerScrollView.h"
@interface TickerScrollView()
- (void)initialiseTextLabel;
- (void)clearTicker;
- (void)beginAnimation;
@end
@implementation TickerScrollView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
[self setFrame: frame];
[self setBounces: NO];
[self setUserInteractionEnabled:NO];
[self setShowsVerticalScrollIndicator:NO];
[self setShowsHorizontalScrollIndicator:NO];
[self initialiseTextLabel];
}
return self;
}
- (void)initialiseTextLabel {
textLabel = [[[UILabel alloc] initWithFrame:self.bounds] autorelease];
[textLabel setTextAlignment:UITextAlignmentLeft];
[textLabel setNumberOfLines:1];
[textLabel sizeToFit];
[self addSubview:textLabel];
[self sendSubviewToBack:textLabel];
[self setScrollEnabled:YES];
}
- (void)displayText:(NSString *)string {
[self clearTicker];
[textLabel setText:string];
[textLabel sizeToFit];
[self setContentSize:textLabel.frame.size];
[self beginAnimation];
}
- (void)clearTicker {
[textLabel setText:@""];
[textLabel sizeToFit];
CGPoint origin = CGPointMake(0, 0);
[self setContentOffset:origin];
}
- (void)beginAnimation {
CGFloat text_width = textLabel.frame.size.width;
CGFloat display_width = self.frame.size.width;
if (text_width > display_width) {
CGPoint origin = CGPointMake(0, 0);
[self setContentOffset:origin];
CGPoint terminal_origin = CGPointMake(textLabel.frame.size.width - self.frame.size.width, textLabel.frame.origin.y);
float duration = (text_width - display_width)/50;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelay:1.0];
[UIView setAnimationDuration:duration];
[self setContentOffset:terminal_origin];
[UIView commitAnimations];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)dealloc {
[textLabel release];
[super dealloc];
}
@synthesize textLabel;
@end
相關問題
- 1. 如何在我的iPhone應用程序中實現FmDatabase?
- 2. 如何在我的應用程序中實現我的代碼中的ASyncTask
- 3. 如何在iPhone應用程序中實現QR碼閱讀器
- 4. 如何在iPhone應用程序中實現密碼恢復?
- 5. 如何在我的iPhone應用程序中實現QR碼閱讀器
- 6. 我想在我的iPhone應用程序中實現OCR
- 7. 在iPhone應用程序的IAd實現
- 8. 在應用程序中實現iPhone應用程序
- 9. 在iphone應用程序中實現應用程序細化
- 10. 在我的iphone中實現空閒時間應用程序
- 11. 如何在我們的android應用程序中實現其他應用程序的代碼?
- 12. 如何在iPhone應用程序中實現Wikitude API?
- 13. 如何在iPhone應用程序中實現adwhirl?
- 14. 如何在iphone中實現應用程序多語言選擇?
- 15. 如何在iphone應用程序中實現RSA算法?
- 16. 如何在iPhone應用程序中實現訂閱計劃
- 17. 如何在iphone應用程序中實現PSCollectionView?
- 18. 如何在iPhone應用程序中實現廣告?
- 19. 如何在pdf中爲iphone應用程序實現分頁?
- 20. 如何在iPhone應用程序開發中實現instapaper?
- 21. 如何在iphone應用程序中實現Facebook評論
- 22. 如何在iPhone中實現iAD到應用程序?
- 23. 如何在iPhone應用程序中實現頁面控制?
- 24. 如何在iPhone應用程序中實現GPS?
- 25. 如何在iphone應用程序中實現twitter
- 26. 如何在iPhone應用程序中實現語言翻譯?
- 27. 我如何在我的應用程序中實現雲計算?
- 28. 如何在我的iPhone/iPad應用程序中實現此目的?
- 29. 在我的iPhone應用程序中,我試圖在Tableview中實現UISearchBar
- 30. iphone應用程序中的weblink實現
您可能需要確定__A ticker__多一點對我們幫助你;) – deanWombourne 2010-07-02 12:15:52
誰投票決定關閉這個問題應該由現在已經學會這是你要求海報澄清的那種問題,而不是你過於模糊的那種問題。 – 2010-07-02 14:25:15
可能的重複[有沒有人有一個很好的方法來滾動文字到一邊,就像在iPhone應用程序中的筆尖上的標籤上的股票報價?](http://stackoverflow.com/questions/900425/does-任何人都有一個很好的方式滾動文本關閉到一邊就像一個股票股票代碼我) – 2010-07-02 14:32:52