2013-08-01 25 views
0

我的應用程序需要使用自動滾動來滾動不同文章的標題。當我點擊文章的任何部分時,該特定文章的細節應該顯示。如何在iOS 5,6中創建可點擊的自動滾動?

我已經嘗試了很多東西,還有很多方法。沒有人似乎完美地工作。與最有希望的方法是,我用自動滾屏從AutoScrollLabel

,也爲可點擊文本上的UI標籤RichUILabels

,我這個面臨的一個小問題,目前是被顯示爲文本可點擊的只是一個字而不是整個句子。如果有幫助,我可以在這些文章標題之間添加特定的分隔符。但即使如此,我仍然不確定如何將完整的句子作爲突出顯示的文本。

有沒有更簡單的方法來做到這一點?

  1. 隨時給我一個全新的方法。
  2. 或者,如果這可以通過簡單地使用多個AutoScrollLabels

來完成請讓我知道如果你需要這方面的任何詳細信息。

+0

您可以通過集成以下解決方案嘗試 http://stackoverflow.com/a/12856174/1228669 http://stackoverflow.com/a/3694455/1228669 基本想法是創建一個具有無限滾動視圖按鈕並使用計時器滾動它 – prasad

+0

謝謝..這看起來很有趣。不過這是一種解決方法。 – utsavanand

回答

0

您可以動態生成UIScrollView中的UIButton併爲其指定一個目標以重定向到下一個屏幕。看看下面的代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    //[myMapView addAnnotation:(id<MKAnnotation>)]; 

    int y=10; 

    for(int i=0;i<10;i++) 
    { 

     CGRect frame = CGRectMake(10, y, 280, 40); 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
     button.frame = frame; 
     button.tag=i; 
     [button setTitle:(NSString *)@"new button" forState:(UIControlState)UIControlStateNormal]; 
     [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
     [myScroll addSubview:button]; 

     y+=45; 
    } 
} 

- (空)buttonTapped:(ID)發送

{ 
    // code for redirecting to another view 
    // use button tag property for identifying perticular record 

} 

可以文章標題分配到按鈕上的文字。將文章數據存儲在數組中,並按照以下方式進行分配。

[button setTitle:(NSString *)[tempArray objectAtIndex:i] forState:(UIControlState)UIControlStateNormal]; 

希望這會幫助你。

+0

好的。嗯..但我認爲這不會讓我自動滾動? – utsavanand

+0

自動滾動的意義?沒有得到完全... – hpp

+0

自動滾動如標籤上的文字應自動滾動,就像一個選框。 – utsavanand

0

您好,請試試這個代碼:

float alph = 0.7; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    glowLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)]; 
    NSString *string = @"some text"; 
    glowLabel.text = string; 
    glowLabel.textColor = [UIColor blueColor]; 
    [self.view addSubview:glowLabel]; 
    glowLabel.alpha = alph; 
    [NSTimer scheduledTimerWithTimeInterval:0.4 
            target:self 
            selector:@selector(glowMarquee) 
            userInfo:nil 
            repeats:YES]; 
} 

-(void)glowMarquee { 
    alph = (alph == 1) ? 0.7 : 1; // Switch value of alph 
    [UIView beginAnimations:@"alpha" context:NULL]; 
    [UIView setAnimationDuration:0.4];   
    glowLabel.alpha = alph; 
    [UIView commitAnimations]; 
} 

使用此代碼,同時創造的文章列表生成標籤。希望這會幫助你。