【问题标题】:Graphic spot appearing on the screen when customizing UIActionSheet自定义 UIActionSheet 时出现在屏幕上的图形点
【发布时间】:2014-03-06 20:07:38
【问题描述】:

当我自定义UIActionSheet 时,屏幕上出现了一个图形白点。

当我将 *background 设置为透明以外的任何其他颜色时,图形白点消失...

截图:

这是我的代码:

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

有人有解决办法吗? 非常感谢。

【问题讨论】:

  • 解决方案是不要以 Apple 不支持的方式滥用UIActionSheet。查找一些提供UIActionSheet 的可自定义替换的第三方库或类。
  • 如果根本不添加背景视图会怎样?背景视图有什么用?
  • @MarcusAdams 没有背景结果完全一样。
  • 好吧,你没有从UIActionSheet 中得到任何东西,所以尝试使用具有半透明背景的普通UIView
  • @MarcusAdams 我会这样做的。谢谢

标签: ios objective-c customization uiactionsheet


【解决方案1】:

UIActionSheet 不是为子类而设计的,您也不应该在其层次结构中添加视图。如果您需要提供比UIActionSheet API 提供的更多自定义的工作表,您可以创建自己的工作表并使用presentViewController:animated:completion: 模态显示。

基于:UIActionSheet Class Reference

【讨论】:

  • 您可能不想创建视图控制器并以模态方式呈现它。这仅在您使用导航控制器并且仅在某些 iOS 版本上有效。只需使用子视图。
猜你喜欢
  • 1970-01-01
  • 2021-03-19
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
  • 1970-01-01
  • 2016-09-22
相关资源
最近更新 更多