How to add marquee to a label

前端 未结 2 853
庸人自扰
庸人自扰 2020-12-29 00:27

I have a label at the top of my UIView.I am displaying some messages on it through array with the help of the timer.But now i want this messages to be displayed in MARQUEE s

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 00:52

    I followed your idea, and I did that:

    *I Created a container view.

    messageView = [[UIView alloc] initWithFrame:CGRectMake(27, 0, 235, 19)];
    [messageView setClipsToBounds:YES];//With This you prevent the animation to be drawn outside the bounds.
    

    *Then I created a UILabel with the text to be displayed and added to my container view

    lblTime = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 235, 19)];
    [lblTime setBackgroundColor:[UIColor clearColor]];
    [messageView addSubview:lblTime];
    

    *Finally I created a function like this:

    - (void)sendNotification:(NSString*)txt{
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:3.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
        [lblTime setText:txt];
        [lblTime setTextAlignment:UITextAlignmentLeft];
        lblTime.frame = CGRectMake(260, 0, 258, 19);
        [UIView commitAnimations];
    }
    

提交回复
热议问题