UIActionSheet的背景没有设置

时间:2016-05-10 07:32:15

标签: ios uiactionsheet

我一直在关注此链接以完成我的任务。我想让我的 UIActionSheet 背景变灰。但是在发布后没有任何反应!我也尝试了其他的东西!! iPhone development: How to create colored or translucent background for UIActionSheet?

到目前为止我做了什么:

ON .h文件:

添加了 UIActionSheetDelegate 和一个属性

@property (strong, nonatomic) UIActionSheet *popupDelete;

在.m文件中:

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:

enter image description here

如何让它发挥作用!!!

1 个答案:

答案 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.如果您不想更改类型,则可以设置颜色

  • 添加QuartzCore.framework

在您的课程中复制以下方法

actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent;

如果您有任何问题,请告诉我。