iPhone development: How to create colored or translucent background for 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 创建彩色或半透明背景?
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
