UITableView分组设置背景颜色透明

时间:2016-05-27 12:12:12

标签: ios uitableview uiviewcontroller uimodalpresentationstyle

这就是我的观点:

enter image description here

这就是我想要的方式(忽略文字颜色)

enter image description here

您可以看到标题之间的视图应该被清除。但那并没有发生 这就是我实现模态ViewController的方法:

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

ActivityFilterViewController

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

5 个答案:

答案 0 :(得分:0)

如果Privacy Parameter,则应将模态演示风格设置为ios version is lower then 8.0UIModalPresentationCurrentContext。像,

self

如果您正在使用导航控制器,

   self.modalPresentationStyle = UIModalPresentationCurrentContext;

如果两个navihation控制器到达此视图,那么

  self.nnavigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

如果ios版本为 self.navigationController.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext; ,则模态演示文稿样式应为greater or equal to 8.0,并且应设置为您要呈现的视图控制器,

UIModalPresentationOverCurrentContext

如果您已进行此设置,请检查您的每个图层的背景颜色是否设置为过滤器VC的 filter.modalPresentationStyle = UIModalPresentationOverCurrentContext;

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

希望这会有所帮助:)

答案 1 :(得分:0)

使用自定义视图控制器。不是ActivityController。 无论如何设计它并在当前环境中呈现它。

不需要UITableView,因为你还是不滚动它。

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

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

答案 2 :(得分:0)

您可以将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];

答案 3 :(得分:0)

步骤1&其他人已经说过下面的2了,但是为了完整答案,我还是会在这里说出来。

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

self.tableView.backgroundColor = [UIColor clearColor];

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

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

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

- (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视图中),但这会增加更多空间顶部(第一个细胞)或顶部和顶部部分中单元格的底部(最后一个单元格)。

答案 4 :(得分:0)

试试这个:

viewDidLoad中:

tableView.backgroundColor = [UIColor clearColor];

或以上不起作用,

tableView.backgroundView = nil;
相关问题