开发者

How to create Custom alert with image in cocoa touch

I need a UIAlert with image.As far as i know UIAlertView does not have a constructor which takes image.So now i开发者_运维问答 need to create customAlertView. But i dont know how to do it.Is customAlertView will be a subclass of UIAlertView so that it takes the delegate method of UIAlertView or what???i search a lot but did not find a implementation of customAlertView.I am new to cocoa touch framework and dont have the expertise to do it myself.so plz someone help me.plz give me some implementation ,not just the logic.waiting for your answer.


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜