我一直在关注此链接以完成我的任务。我想让我的 UIActionSheet 背景变灰。但是在发布后没有任何反应!我也尝试了其他的东西!! iPhone development: How to create colored or translucent background for UIActionSheet?
到目前为止我做了什么:
添加了 UIActionSheetDelegate 和一个属性
@property (strong, nonatomic) UIActionSheet *popupDelete;
self.popupDelete = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Remove",nil];
self.popupDelete.tag = sender.tag;
[self.popupDelete showInView:self.view];
然后添加了上面帖子中提到的委托方法:
- (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];
}
图片detail_menu_bg.png:
如何让它发挥作用!!!
答案 0 :(得分:0)
1.如果您使用背景颜色而不是显示背景图像,则可以使用actionsheetstyle来更改颜色。
OSStatus error;
AudioDeviceID deviceID = 0;
AudioObjectPropertyAddress propertyAddress;
UInt32 propertySize;
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(AudioDeviceID);
error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject,
&propertyAddress,
0,
NULL,
&propertySize,
&deviceID);
if(error)
return error;
propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(Float64);
error = AudioHardwareServiceGetPropertyData(deviceID,
&propertyAddress,
0,
NULL,
&propertySize,
outSampleRate);
或
actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackOpaque
2.如果您不想更改类型,则可以设置颜色
在您的课程中复制以下方法
actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
如果您有任何问题,请告诉我。