我需要一个带图像的UIAlert。据我所知,UIAlertView没有一个构造函数来获取image.So现在我需要创建customAlertView。但我不知道怎么做。是customAlertView将是UIAlertView的子类,所以它采取UIAlertView的委托方法或什么???我搜索了很多但没有找到customAlertView的实现。我是cocoa触摸的新手框架,并没有自己的专业知识。所以有人帮助我.plz给我一些实现,而不仅仅是逻辑。等待你的答案。
答案 0 :(得分: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];