我正在尝试更改uialertview的背景。 一切正常,除了我添加到uialert视图的背景图像不会在alertview内缩放。因此,基本上您只能看到基于当前大小的背景图像的一部分。 是否有任何方法可以使图像在alerview内缩放直到它适合?
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[theAlert show];
UIImage *theImage = [UIImage imageNamed:@"bg.jpg"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theAlert.frame.size.width, theAlert.frame.size.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
theAlert.layer.contents = (id)[theImage CGImage];
[theAlert release];
答案 0 :(得分:5)
请看一下: http://joris.kluivers.nl/iphone-dev/?p=CustomAlert
他们通过继承UIAlertView来解释如何做到这一点。祝你好运!