2010-10-12 70 views
1

我需要一個UIAlert與圖像。據我所知UIAlertView沒有一個構造函數,它需要image.So現在我需要創建customAlertView。但我不知道如何去做。是否customAlertView將是UIAlertView的一個子類,以便它採用UIAlertView的委託方法或者什麼?我搜索了很多,但沒有找到customAlertView的實現。我是可可觸摸的新手框架,並沒有專業知識來做到這一點。因此,有人幫助me.plz給我一些實現,而不僅僅是邏輯,等待你的答案。如何創建與可可觸摸圖像的自定義警報

回答

2

試試這個:

NSString *title = [NSString stringWithFormat:@"YOUR TITLE"]; 
    NSString *alertMessage = [NSString stringWithFormat:@"YOUR MESSAGE"]; 
    NSString *button1 = [NSString stringWithFormat:@"your button 1"]; 
    NSString *button2 = [NSString stringWithFormat:@"your button 2"]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:alertMessage delegate:self cancelButtonTitle:button1 otherButtonTitles:button2, nil]; 

    UIImage *alertImage = [UIImage imageNamed:@"your image"]; 

    UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage]; 
    backgroundImageView.frame = CGRectMake(0, 0, 282, 130); 
    backgroundImageView.contentMode = UIViewContentModeScaleToFill; 

    [alert addSubview:backgroundImageView]; 
    [alert sendSubviewToBack:backgroundImageView]; 
    [alert show]; 
    [alert release];