0

我的应用程序需要自动滚动,其中不同文章的标题滚动。当我点击任何一篇文章时,应该会显示该特定文章的详细信息。

我尝试了很多东西,也尝试了很多方法。似乎没有一个工作完美。最有希望的方法是我使用AutoScrollLabel中的自动滚动

也适用于 UI-Label RichUILabels上的可点击文本

我目前面临的一个小问题是显示为可点击的文本只是一个单词而不是整个句子。如果有帮助,我可以在这些文章标题之间添加特定的分隔符。但即使如此,我仍然不确定如何将完整的句子作为突出显示的文本。

有没有更简单的方法来做到这一点?

  1. 随意向我推荐一种全新的方法。
  2. 或者,如果这可以通过简单地使用多个 AutoScrollLabels 来完成

如果您需要有关此的更多信息,请告诉我。

4

2 回答 2

0

您可以在 UIScrollView 中动态生成 UIButtons 并为其分配一个目标以重定向到下一个屏幕。看下面的代码:

- (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;
    }
}

-(void)buttonTapped:(id)sender

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

}

您可以将文章的标题分配给按钮文本。将文章数据存储在数组中并按以下方式分配。

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

希望这会帮助你。

于 2013-08-01T12:12:25.573 回答
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];
}

在创建文章列表时使用此代码生成标签。希望这会帮助你。

于 2013-08-02T04:05:34.943 回答