1

在 android 中,我们可以有一个警报对话框,其中包含如下图所示的项目列表:

在此处输入图像描述

但是对于 iPhone 案例,我们如何创建这样的警报视图?

4

2 回答 2

1

您需要使用代理名称和电话属性创建 MyCustomAlertViewController。创建 xib 。之后这样写:

- (void) alertForAgentName: (NSString*) anAgentName agentPhoneNumber: (NSString*) anAgentPhoneNumber
{
    MyCustomAlertViewController* modalViewController =
        [[MyCustomAlertViewController alloc] initWithNibName: @"MyCustomAlertViewController" bundle:nil];

    modalViewController.agentName = anAgentName;
    modalViewController.agentPhoneNumber = anAgentPhoneNumber;

    UINavigationController *modalViewNavController =
        [[UINavigationController alloc]
        initWithRootViewController: modalViewController];

    [self.navigationController presentModalViewController:
        modalViewNavController animated:YES];
    // If MRC
    [modalViewNavController release];
}

对于关闭对话框,您需要像这样调用(它在 MyCustomAlertViewController 类中):

- (IBAction) dismissModalView:(id)sender
{
    [self.parentViewController dismissModalViewControllerAnimated:NO];
}
于 2013-06-29T06:06:17.933 回答
0

您可以像这样创建警报

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UILabel *labelone = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labelone.text=@"label1";
[labelone setBackgroundColor:[UIColor clearColor]];
[labelone setTextAlignment:UITextAlignmentLeft];

UILabel *labeltwo = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labeltwo.text=@"label2";
[labeltwo setBackgroundColor:[UIColor clearColor]];
[labeltwo setTextAlignment:UITextAlignmentLeft];

UILabel *labelthree = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labelthree.text=@"label3";
[labelthree setBackgroundColor:[UIColor clearColor]];
[labelthree setTextAlignment:UITextAlignmentLeft];

[alert addSubview:labelone];
[alert addSubview:labeltwo];
[alert addSubview:labelthree];

[alert setDelegate:self];
[alert show];
[alert release];

如果要调整警报视图的帧大小,可以使用

- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 150.f);
NSArray *subViewArray = alertView.subviews;
for(int x=0;x<[subViewArray count];x++){
    if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
    {
        UILabel *label = [subViewArray objectAtIndex:x];
        label.textAlignment = UITextAlignmentLeft;
    }
}

}

于 2013-06-29T05:48:09.137 回答