2011-05-23 84 views
0

我已經有一個自定義的UIAlertView,並且我想在其中添加UIImageView以添加自定義的UIAlertView。我可以在自定義UIAlertView中添加UIImageView嗎?

我已經添加了UIImageView與數組,並開始動畫它,但它不工作。如果你願意,我可以發佈代碼。

請儘快幫我。我卡:(

這裏是代碼

- (id)initWithImage:(UIImage *)image text:(NSString *)text 
{ 

    //CGSize imageSize = self.backgroundImage.size; 
    CGRect frame = [[UIScreen mainScreen] bounds]; 

    width = frame.size.width; 
    height = frame.size.height; 

    if (self = [super init]) 
    { 



     loadtext = [[UILabel alloc]initWithFrame:CGRectZero]; 
     loadtext.textColor = [UIColor blackColor]; 
     loadtext.backgroundColor = [UIColor whiteColor]; 
     [self addSubview:loadtext]; 

     //Create the first status image and the indicator view 
     UIImage *statusImage = [UIImage imageNamed:@"status1.png"]; 
     activityImageView = [[UIImageView alloc] 
              initWithImage:statusImage]; 


     //Add more images which will be used for the animation 
     activityImageView.animationImages = [NSArray arrayWithObjects: 
              [UIImage imageNamed:@"status1.png"], 
              [UIImage imageNamed:@"status2.png"], 
              [UIImage imageNamed:@"status3.png"], 
              [UIImage imageNamed:@"status4.png"], 
              [UIImage imageNamed:@"status5.png"], 
              [UIImage imageNamed:@"status6.png"], 
              [UIImage imageNamed:@"status7.png"], 
              nil]; 


     //Set the duration of the animation (play with it 
     //until it looks nice for you) 
     activityImageView.animationDuration = 1.0; 


     //Position the activity image view somewhere in 
     //the middle of your current view 
     activityImageView.frame = CGRectZero; 

     //Start the animation 
     [activityImageView startAnimating]; 


     //Add your custom activity indicator to your current view 
     [self addSubview:activityImageView]; 



     //self.backgroundImage = image; 



    } 
    return self; 
} 

- (void) layoutSubviews{ 
    //lblUserName.transform = CGAffineTransformMake; 
    //[lblUserName sizeToFit]; 

    CGRect textRect = activityImageView.frame; 
    textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect))/2; 
    textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect))/2; 
    textRect.origin.x -= 100.0; 
    textRect.origin.y -= 60.0; 
    textRect.size.height = 30; 
    textRect.size.width = self.bounds.size.width - 50; 

    activityImageView.frame = textRect; 
} 

此代碼開始工作。但是,現在這是UIImageView的把我的整個屏幕,並在UIAlertView中。雖然前面來了我給10px的高度和寬度。這顯示同一誰能幫助請

感謝, Anks

+0

你可以張貼的代碼,你的圖像添加到警報看法? – 2011-05-23 07:08:43

+0

好的,我已經編輯了這個問題並添加了代碼 – Anks 2011-05-23 07:11:20

回答

0

是的,你可以添加圖像視圖 - ?自定義警報的視圖,而不是採取作爲UIView的自定義類,需要採取的UIImage - 視圖&你。可以使用我法師視圖屬性。

+0

你能舉個例子嗎? – Anks 2011-05-23 07:30:25

0

變化activityImageView.frame = CGRectZero;

一些自定義的框架。

如:

activityImageView.frame = CGRectMake(0,0,100,100); 
+0

它已經將layoutSubview並更改它。我已經嘗試過,但它不工作:( – Anks 2011-05-23 07:46:52

相關問題