改变uialertview大小的问题

mru*_*gen 9 iphone sdk xcode uialertview

您好我有一个alertview,我想通过cgrectmake属性更改大小,但它不会发生.它只取默认大小.

我试过以下代码.

- (void)viewDidLoad {
[super viewDidLoad];
UIAlertView* find = [[[UIAlertView alloc] init]initWithFrame:CGRectMake(0,0,300,200)];
[find setDelegate:self];
[find setTitle:@"Sample Alert"];
[find setNeedsLayout];
[find show];
[find release];
Run Code Online (Sandbox Code Playgroud)

}

提前致谢 .

ahm*_*rah 16

要在您的代码中实现您想要的目标,请执行以下操作:

[find show];
Run Code Online (Sandbox Code Playgroud)

加:

find.frame = CGRectMake(0,0,300,200);
Run Code Online (Sandbox Code Playgroud)

虽然它不漂亮,我建议你使用ActionSheets.


Pan*_*hla 7

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:@" Submit the answer " delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[alert show];
[alert release];

UILabel *theTitle = [alert valueForKey:@"_titleLabel"];
[theTitle setTextColor:[UIColor blackColor]];

UILabel *theBody = [alert valueForKey:@"_bodyTextLabel"];
[theBody setTextColor:[UIColor blackColor]];

UIImage *theImage = [UIImage imageNamed:@"blue-white-abstract-background.jpg"];    
theImage = [theImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];
CGSize theSize = [alert frame].size;

UIGraphicsBeginImageContext(theSize);    
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
theImage = UIGraphicsGetImageFromCurrentImageContext();    
UIGraphicsEndImageContext();

//[[alert layer] setContents:[theImage CGImage]];
[[alert layer] setContents:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)

此代码对alertview执行了很多操作,并对其进行了修改以增加警报视图的大小.


小智 7

这很好地完成了工作,并且当警报出现时看起来并不奇怪(ahmet emrah解决方案有非常糟糕的副作用).

CGAffineTransform myTransform = CGAffineTransformMakeScale(1.0, 0.5f);
[alert setTransform:myTransform];
Run Code Online (Sandbox Code Playgroud)