2012-10-17 49 views
0

我嘗試將動畫圖像設置爲UILabel背景。我的標籤從點(x = 0 y260到x = 480 y = 260)移動,我想在動畫過程中添加UIImage。因此,對於我嘗試這樣如何將動畫圖像設置爲UILabel背景?

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]; 

我設置的UILabel背景與單個的UIImage喜歡這個

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

單幅圖像代碼的工作,但是當我嘗試用動畫圖像來實現它(如上我代碼顯示),那麼它不是作品能有人指導我如何設置動畫圖像作爲一個UILabel Background.Thanx

+0

你被困在一個帶有清晰背景的標籤後面。如果您擔心想讓動畫隨標籤一起移動,請將它們放在另一個UIView中,然後移動它。 – 2012-10-17 19:01:15

回答

0

首先,不添加的UIImageView標註爲子視圖與[lbl1 addSubview:myimg];

首先添加imageview,然後將uilabel添加到它。您的標籤將透明並浮動在uiimageview上。

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

+0

該標籤沒有透明背景..你必須使它透明'lbl1.backgroundColor = [UIColor clearColor]' – Bastian

+0

可以添加imageview到uilabel.beacuse我的UILabel沿着屏幕移動,所以它不適合我創建在特定點imageview這就是爲什麼我需要添加uiimageview在我的UILabel。 – jamil

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]; 
+0

該標籤沒有透明背景..你必須使它透明'lbl1.backgroundColor = [UIColor clearColor]' – Bastian

+0

是啊錯過了編輯添加 –

+0

它可以添加imageview到uilabel.beacuse我的UILabel沿屏幕移動它不適合我在特定點創建imageview,這就是爲什麼我需要在我的UILabel中添加uiimageview。 – jamil

0

在IOS 7此工作

[myLabel setBackgroundColor:的UIColor colorWithPatternImage:[UIImage的imageNamed:@ 「panel_dev_header」]]];