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 创建彩色或半透明背景?


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01