我尝试将动画图像设置为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];
单个图像代码可以工作,但是当我尝试使用Animates图像实现它时(如上面我的代码显示)那么它不起作用可以有人指导我如何将动画图像设置为UILabel Background.Thanx
答案 0 :(得分: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];
答案 1 :(得分:0)
首先,不要将UIImageView添加到标签为[lbl1 addSubview:myimg];
首先添加imageview,然后将uilabel添加到它上。您的标签将是透明的并浮动在uiimageview上。
您可能还需要[imageView setuserinteractionEnabled:YES];
来查看uiimageview。
答案 2 :(得分:0)
iOS 7中的这项工作
[myLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@“panel_dev_header”]]];