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 创建彩色或半透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

基础教程推荐