2014-03-06 67 views
2

當我自定義UIActionSheet時,屏幕上出現圖形白點。自定義UIActionSheet時出現在屏幕上的圖形點

圖形白斑消失,當我設置*背景爲任何其他顏色較透明...

截圖:

enter image description here

這裏是我的代碼:

- (void) customisingActionSheet 
{ 

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

    UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0,0,320, 315)]; 
    background.backgroundColor = [UIColor clearColor]; 
    [actionSheet addSubview:background]; 

    self.customActionSheet = actionSheet; 



    UIButton *cancelButton = [UIButton buttonWithType: UIButtonTypeCustom]; 
    cancelButton.frame = CGRectMake(15, 111, 290, 45); 
    [cancelButton addTarget:self action:@selector(cancelButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    cancelButton.adjustsImageWhenHighlighted = YES; 
    [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; 
    [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
    cancelButton.backgroundColor = darkGrey; 
    cancelButton.titleLabel.textAlignment = NSTextAlignmentCenter; 
    cancelButton.titleLabel.font = [UIFont fontWithName: @"HelveticaNeue-Medium" size: 17]; 
    [self.customActionSheet addSubview: cancelButton]; 

    UIButton *chooseFromLibrary = [UIButton buttonWithType: UIButtonTypeCustom]; 
    chooseFromLibrary.frame = CGRectMake(15, 52, 290, 45); 
    [chooseFromLibrary addTarget:self action:@selector(emailResultsTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    chooseFromLibrary.adjustsImageWhenHighlighted = YES; 
    [chooseFromLibrary setTitle:@"Choose from Library" forState:UIControlStateNormal]; 
    [chooseFromLibrary setTitleColor:[UIColor colorWithRed:53/255.0f green:53/255.0f blue:53/255.0f alpha:1.0f] forState:UIControlStateNormal]; 
    chooseFromLibrary.backgroundColor = [UIColor whiteColor]; 
    chooseFromLibrary.titleLabel.textAlignment = NSTextAlignmentCenter; 
    chooseFromLibrary.titleLabel.font = [UIFont fontWithName: @"Helveticaneue" size: 17]; 
    [self.customActionSheet addSubview: chooseFromLibrary]; 

    UIButton *takePicture = [UIButton buttonWithType: UIButtonTypeCustom]; 
    takePicture.frame = CGRectMake(15, 0, 290, 45); 
    [takePicture addTarget:self action:@selector(emailResultsTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    takePicture.adjustsImageWhenHighlighted = YES; 
    [takePicture setTitle:@"Take picture" forState:UIControlStateNormal]; 
    [takePicture setTitleColor:[UIColor colorWithRed:53/255.0f green:53/255.0f blue:53/255.0f alpha:1.0f] forState:UIControlStateNormal]; 
    takePicture.backgroundColor = [UIColor whiteColor]; 
    takePicture.titleLabel.textAlignment = NSTextAlignmentCenter; 
    takePicture.titleLabel.font = [UIFont fontWithName: @"Helveticaneue" size: 17]; 
    [self.customActionSheet addSubview: takePicture]; 


    [actionSheet showInView:self.view]; 
    [self.customActionSheet setBounds:CGRectMake(0,0,320, 315)]; 
} 

任何人都有解決方案嗎? 非常感謝。

+0

解決的辦法是不要濫用'UIActionSheet'在不被蘋果公司支持的一種方式。找到一些爲UIActionSheet提供可定製替換的第三方庫或類。 – rmaddy

+0

如果您根本不添加背景視圖,會發生什麼情況?背景視圖是什麼? –

+0

@MarcusAdams沒有背景,結果完全一樣。 –

回答

0

UIActionSheet沒有設計成被繼承,也不應該你添加的意見它的層次結構。如果您需要提供比UIActionSheet API提供的定製更多的表單,則可以創建自己的表單並以presentViewController:animated:completion:的形式呈現。

基於:UIActionSheet Class Reference

+0

我會這麼做的。謝謝 –

+0

您可能不想創建視圖控制器並以模態方式呈現它。這隻適用於您使用導航控制器並且僅適用於某些iOS版本的情況。只需使用子視圖。 –