ios的文字滚动

来源:互联网 发布:淘宝开店注册账号 编辑:程序博客网 时间:2024/04/29 19:19

@property (weak,nonatomic) IBOutletUILabel *textNameLabel;


@property (nonatomic,strong)NSMutableArray *textArray;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    CALayer *subLayer = [CALayerlayer];


    [subLayer setBounds:CGRectMake(0,0, 200,200)];

    

    [subLayer setPosition:CGPointMake(100,100)];

    

    [subLayer setBackgroundColor:[UIColorredColor].CGColor];

    

    [self.view.layeraddSublayer:subLayer];

    

    

    self.textArray = [NSMutableArrayarrayWithObjects:@"他就会很健康很好",@"海陆空艰苦奋斗了",@"sggsffgs",@"这个减肥的空间",nil];

    

    

}


//改变文字

- (IBAction)changeTestAction:(UIButton *)sender {

    

    staticint i=0;

    

    if (i==3) {

        

        i=0;

    }else

    {

        i++;

    }

    

    self.textNameLabel.text =self.textArray[i];



    CATransition *transition = [[CATransitionalloc] init];

    

    transition.type =@"push";

    

    transition.subtype =kCATransitionFromTop;

    

    transition.duration=0.1;

    

    [self.textNameLabel.layeraddAnimation:transition forKey:nil];

    

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

0 0
原创粉丝点击