Abin George
Abin George

Reputation: 654

UIActionsheet background clear color

enter image description here Here am having an actionsheet with custom elements. Now, i need the background of the actionsheet clear color, or it should work like a mirror. Any idea ? plz help. But currently it is returning a light grey shade. What should i do?

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

}

Above shown is the image of the actionsheet am getting.

Upvotes: 0

Views: 531

Answers (1)

user3278923
user3278923

Reputation:

I usually implement the following delegate method:

-add QuartzCore.framework .
-set delegate for your actionsheet
-set style for actionsheet: UIActionSheetStyleBlackTranslucent
-override method 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];
}

Upvotes: 1

Related Questions