iPhone开发:如何为UIActionSheet创建彩色或半透明背景? [英] iPhone development: How to create colored or translucent background for UIActionSheet?

查看:86
本文介绍了iPhone开发:如何为UIActionSheet创建彩色或半透明背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您尝试删除iPhone的Notes应用程序中的注释时,会弹出一个UIActionSheet。该片材是半透明的(但不是半透明的黑色)。这是如何实现的?是否有可能使UIActionSheet的背景成为某种颜色?

When you try deleting a note in iPhone's Notes application, an UIActionSheet pops up. The sheet is translucent (but not black translucent). How is that achieved? Is it possible to make the background of UIActionSheet a certain color?

推荐答案

我通常实现以下委托方法:

I usually implement the following delegate method:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet

只是为了做样品。在这种情况下,我使用拉伸的png作为背景:

Just to make a sample. In this case I use a stretched png as a background:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    UIImage *theImage = [UIImage imageNamed:@"detail_menu_bg.png"];    
    theImage = [theImage stretchableImageWithLeftCapWidth:32 topCapHeight:32];
    CGSize theSize = actionSheet.frame.size;
    // draw the background image and replace layer content  
    UIGraphicsBeginImageContext(theSize);    
    [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
    theImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    [[actionSheet layer] setContents:(id)theImage.CGImage];
}

这就是结果:
替代文字http://grab.by/4yF1

这篇关于iPhone开发:如何为UIActionSheet创建彩色或半透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆