2013-06-28 49 views
0

想知道正確的方法是將初始化我警報彈出一個小窗口更改警報信息的寬度和高度的i-電話

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

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

} 
+0

UIAlertView繼承自UIView,因此它具有框架屬性。我不知道調整是否會起作用,但值得一試。 –

回答

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位置,寬度,高度)。改變它,你的工作將完成。

+0

謝謝!我也在尋找改變背景顏色,但每當我把alert1.backgroundColor = [UIColor colorWithRed:...];它改變了邊界而不是實際的背景 –

+0

檢查我發佈的另一個答案,你可以使用這個github.com/goncz9/GRAlertView創建custon alertview。希望能幫助到你。 – 2013-06-29 08:35:53

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