ios - UIActionsheet 背景清晰颜色

标签 ios

enter image description here这里有一个带有自定义元素的操作表。现在,我需要操作表的背景颜色清晰,否则它应该像镜子一样工作。任何想法 ?请帮忙。但目前它正在返回浅灰色阴影。我该怎么办?

-(void)chooseCountry
{

UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"Select Country" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];

countryActionSheet=actionSheet;
actionSheet.backgroundColor=[UIColor clearColor];
actionSheet.actionSheetStyle= UIActionSheetStyleDefault;
countryPicker.dataSource=self;
countryPicker.delegate=self;

UIPickerView *pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 320, 300)];
pickerView.delegate=self;
pickerView.dataSource=self;
countryPicker=pickerView;

UIButton *cancelBtn=[[UIButton alloc]initWithFrame:CGRectMake(200,20, 80, 30)];
[cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelBtn addTarget:self action:@selector(cancelBtnPressed) forControlEvents:UIControlEventTouchUpInside];
[cancelBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal];

UIButton *okBtn =[[UIButton alloc]initWithFrame:CGRectMake(40, 20, 80, 30)];
[okBtn setTitle:@"Done" forState:UIControlStateNormal];
[okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[okBtn addTarget:self action:@selector(okBtnPressed) forControlEvents:UIControlEventTouchUpInside];
[okBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal];



countryActionSheet.backgroundColor=[UIColor clearColor];
//[countryActionSheet addSubview:imageView];
[countryActionSheet addSubview:cancelBtn];
[countryActionSheet addSubview:okBtn];

[countryActionSheet addSubview:countryPicker];
[countryActionSheet showInView:self.view];
[countryActionSheet setBounds:CGRectMake(0, 0, 320, 400)];

}

上面显示的是正在获取的操作表的图像。

最佳答案

我通常实现以下委托(delegate)方法:

-添加 QuartzCore.framework 。
-为您的操作表设置委托(delegate)
-为actionsheet设置样式:UIActionSheetStyleBlackTranslucent
-重写方法willPresentActionSheet

#import "QuartzCore/QuartzCore.h"
...

yourActionSheet.delegate = self;
yourActionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
...


- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
//Just to make a sample. In this case I use a stretched png as a background:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {

CGSize mySize = myActionSheet.bounds.size;
CGRect myRect = CGRectMake(0, 0, mySize.width, mySize.height);
UIImageView *redView = [[[UIImageView alloc] initWithFrame:myRect] autorelease];
[redView setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]];
[myActionSheet insertSubview:redView atIndex:0];
}

关于ios - UIActionsheet 背景清晰颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22661164/

相关文章:

ios - 由于仅变换层而在 UIView 中发出警告

iOS - UIButton 成为打开键盘的第一响应者

iphone - 第 5 代设备上更大的启动图像

ios - 使用可变参数格式化字符串

ios - scrollToRowAtIndexPath :atScrollPosition causing table view to "jump"

ios - 为什么Deep Link Web URL查询为空

ios - UIImagePickerController 可以用于从文档目录中选择图像吗?

ios - 发生未指定的错误。无法为应用商店创建新的配置文件

iphone - 如何从 WebView 中获取电子邮件地址?

objective-c - 如何在 objective-c 中出现键盘时 ScrollView ?