【问题标题】:UITableView grouped set background colour transparentUITableView 分组设置背景色透明
【发布时间】:2016-09-25 18:45:10
【问题描述】:

这就是我的看法:

这就是我想要的样子(忽略文本颜色)

如您所见,标题之间的视图应该被清除。但这并没有发生。
这就是我实现模态 ViewController 的方式:

ActivityFilterViewController *filter = [[ActivityFilterViewController alloc] init];
    filter.view.backgroundColor = [UIColor clearColor];
    [filter setModalPresentationStyle:UIModalPresentationCurrentContext];
    [self presentViewController:filter animated:YES completion:nil];  

ActivityFilterViewController

我已将UITableView 设置为分组,并将部分页眉和页脚的高度设置为10。还清除了页眉视图的背景颜色。

【问题讨论】:

  • 你是要去掉tableview的背景色还是要去掉兄弟
  • @Anbu.Karthik :我也将其设置为 clearColor
  • @Nitish - 那么你面临的问题是什么
  • @Anbu.Karthik :在第一个屏幕截图中,部分之间的间隙是透明的,但在我的实现中不是。我想将部分之间的间隙设置为透明

标签: ios uitableview uiviewcontroller uimodalpresentationstyle


【解决方案1】:

试试这个:

viewDidLoad:

tableView.backgroundColor = [UIColor clearColor];

或者上述方法不起作用,

tableView.backgroundView = nil;

【讨论】:

    【解决方案2】:

    如果ios version is lower then 8.0,那么您应该将模态演示样式设置为UIModalPresentationCurrentContextself。比如,

       self.modalPresentationStyle = UIModalPresentationCurrentContext;
    

    如果你使用的是导航控制器,那么

      self.nnavigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
    

    如果两个导​​航控制器都到达这个视图的话,

     self.navigationController.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
    

    如果 ios 版本是 greater or equal to 8.0,那么模态演示样式应该是 UIModalPresentationOverCurrentContext 并且应该设置为您想要呈现的视图控制器,

      filter.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    

    如果您已进行此设置,请检查您的每一层的背景颜色是否设置为过滤器 VC 的clear color

    您应该调试视图层次结构以检查它们之间有多少层。

    希望这会有所帮助:)

    【讨论】:

      【解决方案3】:

      使用自定义视图控制器。不是 ActivityController。 随心所欲地设计它,并在当前上下文中呈现它。

      不需要 UITableView,因为无论如何您都不会滚动它。

      只需为两个子视图使用圆角。

      如果您可以在运行时隐藏一个按钮,您可以使用 UIStackView 以便布局会自动更改。

      【讨论】:

        【解决方案4】:

        您可以将带有UITableView 的子视图添加到UIAlertController

        1 创建 UIAlertController。

            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                           message:nil
                                                                    preferredStyle:UIAlertControllerStyleActionSheet];
        

        2使用UITableView创建子视图

            UIVisualEffect *blurEffect;
            blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        
            UIVisualEffectView *detailsView;
            //Let's match the cornerRadius the iOS Style
            if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
                detailsView = [[UIVisualEffectView alloc] initWithFrame:CGRectMake(0, -120, alertController.view.frame.size.width-20, 110)];
                detailsView.layer.cornerRadius = 15;
            } else {
                detailsView = [[UIVisualEffectView alloc] initWithFrame:CGRectMake(0, -120, alertController.view.frame.size.width-16, 110)];
                detailsView.layer.cornerRadius = 5;
            }
        
            detailsView.effect = blurEffect;
            detailsView.layer.masksToBounds = YES;
            detailsView.alpha = 1;
            detailsView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.74];
        
            //Add the UITableView
            UITableView *menuTableView = [[UITableView alloc]initWithFrame:detailsView.frame style:UITableViewStylePlain];
            [detailsView addSubview:menuTableView];
        

        3添加动作和子视图并呈现UIAlertController

            UIAlertAction* resetAction = [UIAlertAction actionWithTitle:@"Reset to default"
                                                                   style:UIAlertActionStyleDefault
                                                                 handler:^(UIAlertAction * action){
        
            //Reset the switches in your UITableViewCells
        
            }];
        
        
            UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"Save"
                                                                   style:UIAlertActionStyleCancel
                                                                 handler:^(UIAlertAction * action){
        
            //Save 
        
            }];
        
            [alertController addAction:resetAction];
            [alertController addAction:saveAction];
        
            // Add the Subview with the UITableView
            [alertController.view addSubview:detailsView];
        
            [self presentViewController:alertController animated:YES completion:nil];
        

        【讨论】:

          【解决方案5】:

          下面的第 1 步和第 2 步已经被其他人说过了,但是为了我的回答的完整性,我还是要在这里说出来。

          第一步,将表格视图背景设置为透明:

          self.tableView.backgroundColor = [UIColor clearColor];
          

          第 2 步,正如您所说的,您必须通过覆盖 heightForHeaderInSection 方法(在您的情况下为 10)来设置高度:

          - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
          {
              return 50.0;
          }
          

          第 3 步,通过覆盖 viewForHeaderInSection 方法提供自定义视图(注意 - 这是您必须将背景颜色设置为清除的地方):

          - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
          {
              UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.oTableView.frame.size.width, 10)];
              header.backgroundColor = [UIColor clearColor];
          
              return header;
          }
          

          第 4 步,一旦您确认这实际上是在显示透明背景(您将在背景中看到此下方的视图,就像您在上方和侧面看到的一样表格视图),然后专注于在单元格的顶部和底部创建所需的效果。

          您可以通过以下两种方式之一执行此操作:

          1. 修改您的 UITableViewCell 实现以创建圆角(如果部分中的第一个单元格仅左上角和右上角;如果部分中的最后一个单元格仅左下角和右下角)。
          2. 自定义您在viewForHeaderInSection 覆盖中创建的自定义视图以提供圆角效果(将子视图添加到您在此方法中返回的header 视图),但这会在顶部添加更多空间(首先单元格)或部分单元格的顶部和底部(最后一个单元格)。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-04-14
            • 1970-01-01
            • 1970-01-01
            • 2020-03-03
            • 1970-01-01
            • 1970-01-01
            • 2014-09-04
            • 2018-12-25
            相关资源
            最近更新 更多