iPhone 开发:如何为 UIActionSheet 创建彩色或半透明背景?

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

问题描述

当您尝试在 iPhone 的笔记应用程序中删除笔记时,会弹出一个 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 创建彩色或半透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)