跑马灯

来源:互联网 发布:网络信号接收器 编辑:程序博客网 时间:2024/05/16 01:20

UIView*backscrollview=[[UIView alloc]init];

    backscrollview.frame=CGRectMake(10, 13, 100, 18);

    backscrollview.backgroundColor=[UIColor clearColor];

 //需要给标签设置一个父控件,并将溢出的部分屏蔽掉

    backscrollview.clipsToBounds=YES;

    [self.navigationController.navigationBar addSubview:backscrollview];

    

    

  //导航左侧文本

        UILabel*lblScrollLabel=[[UILabel alloc]init];

        lblScrollLabel.text=@"我依然燃烧我仍在信仰";

        lblScrollLabel.font = [UIFont systemFontOfSize:15];

        CGSize lblSize= [HemaFunction getSizeWithStr:lblScrollLabel.text width:150 font:15];

        

        if (lblSize.width>self.frame.size.width)

        {

            lblSize.width=self.frame.size.width;

        }

        lblScrollLabel.frame = CGRectMake(0, 0, lblSize.width, self.frame.size.height);

        lblScrollLabel.backgroundColor = [UIColor clearColor];

        lblScrollLabel.textColor = BB_Blake_Color;

        lblScrollLabel.textAlignment = NSTextAlignmentLeft;

 

  

    lblScrollLabel.frame = CGRectMake(0, (self.frame.size.height-lblSize.height)/2, lblSize.width, self.frame.size.height);

    //实现标签滚动的动画

    CGRect frame = lblScrollLabel.frame;

    frame.origin.x = lblSize.width;

    lblScrollLabel.frame = frame;

 //这个属性是让标签内容自动展示在父控件中和多行展示属性有冲突

    [lblScrollLabel sizeToFit];

    [UIView beginAnimations:@"testAnimation" context:NULL];

    [UIView setAnimationDuration:5];

    [UIView setAnimationCurve:UIViewAnimationCurveLinear];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationRepeatAutoreverses:NO];

    [UIView setAnimationRepeatCount:9999999999999];

    

    frame = lblScrollLabel.frame;

    frame.origin.x = -titlewidth;

    lblScrollLabel.frame = frame;

    [UIView commitAnimations];

     [self addSubview:lblScrollLabel];

0 0
原创粉丝点击