2014-03-26 151 views
0

enter image description here這裏有一個自定義元素的操作表。現在,我需要動作片清晰顏色的背景,或者它應該像鏡子一樣工作。任何想法 ? plz幫助。但目前它正在迴歸淺灰色。我該怎麼辦?UIActionsheet背景清除顏色

-(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)]; 

}

上面顯示的是actionsheet的形象我得到。

回答

1

我通常實現以下代理方法:

-add QuartzCore.framework。
您actionsheet
-set風格actionsheet -set代表:UIActionSheetStyleBlackTranslucent
-override方法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]; 
} 
+0

,但它並沒有爲我改變什麼。還是一樣。 –

+0

我在上面編輯你需要顏色代碼.....我希望它對你有幫助.. – 2014-03-26 12:54:39

+0

該代碼在背景中做了一些改變,但仍保持灰色的顏色在圖像中仍然存在。 –