更改Alert Message i-Phone的宽度和高度

时间:2013-06-28 22:07:25

标签: iphone uialertview

想知道使用较小的窗口初始化我的警报弹出窗口的正确方法

-(void)alertMessage1:(NSString*) title:(NSString*) message1  {

UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Successfully uploaded!" message:message1 delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];

}

3 个答案:

答案 0 :(得分:1)

您应该创建自定义AlertView或使用以下方法之一:

https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=alertview

答案 1 :(得分:1)

您可以按照此建议创建UIAlertview

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Title Here" message:@"Message here" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
                    [alert setDelegate:self];
                    [alert show];
                    [alert release];

如果您想调整框架,请使用

- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.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;
    }

}

}

在此 alertView.frame = CGRectMake(20.f,200.f,280.f,93.f); CGRectMake(X位置,Y位置,宽度,高度) 。改变它,你的工作将完成。

答案 2 :(得分:0)

对于您在评论中提出的问题更改UIAlertview的背景颜色,您可以直接添加这样的背景图片。我不确定你是否可以添加颜色。

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention" message: @"YOUR MESSAGE HERE", nil) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:@"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];