0

我尝试将动画图像设置为 UILabel 背景。我的标签从点 (x=0 y260 移动到 x=480 y=260) 我想在动画期间添加 UIImage。所以我尝试这样

UIImageView *myimg=[[UIImageView alloc]init];
        myimg.animationImages =[NSArray arrayWithObjects:   
                                [UIImage imageNamed:@"1ANI.png"],
                                [UIImage imageNamed:@"2ANI.png"],
                                [UIImage imageNamed:@"3ANI.png"],nil];

        myimg.animationDuration = 1.5;
        myimg.animationRepeatCount = 0;
        [myimg startAnimating]; 
        [lbl1 addSubview:myimg];
        [myimg release];

我像这样使用单个 UIImage 设置 UILabel 背景

UIImage *image=[UIImage imageNamed:@"1ANI.png"];
            lbl2.backgroundColor = [UIColor colorWithPatternImage:image]; 

单个图像代码有效,但是当我尝试使用动画图像实现它(如上面我的代码显示)然后它不起作用有人可以指导我如何将动画图像设置为 UILabel Background.Thanx

4

3 回答 3

1

尝试这个

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 21)];
[label setText:@"asfsdf" ];
[label setBackgroundColor:[UIColor clearColor]];

UIImageView *imagView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 100, 21)];
imagView.animationImages =[NSArray arrayWithObjects:
                        [UIImage imageNamed:@"1ANI.png"],
                        [UIImage imageNamed:@"2ANI.png"],
                        [UIImage imageNamed:@"3ANI.png"],nil];

imagView.animationDuration = 1.5;
imagView.animationRepeatCount = 0;
[imagView startAnimating];
[self.view addSubview:imagView];
[self.view addSubview:label];
于 2012-10-17T14:28:00.277 回答
0

首先不要将 UIImageView 添加到标签为子视图[lbl1 addSubview:myimg];

首先添加图像视图,然后在其上添加 uilabel。您的标签将是透明的并浮动在 uiimageview 上。

您可能还需要 [imageView setuserinteractionEnabled:YES];uiimageview。

于 2012-10-17T13:29:54.107 回答
0

这项工作在 iOS 7

[myLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"panel_dev_header"]]];

于 2014-01-12T23:42:35.977 回答