【问题标题】:display list of images in UITableview with trasparent view在 UITableview 中以透明视图显示图像列表
【发布时间】:2015-02-16 07:04:02
【问题描述】:

您好,我想在 UITableview 中显示图像,而在 uitableview 之上我需要透明视图。

我试过的是:

在故事板和 UITableView 之上添加了视图。

_vaultView.backgroundColor = [UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:0.85f];

Ian 无法显示透明视图。

请建议我如何进行下一步。

编辑:

    - (void)viewDidLoad {
        [super viewDidLoad]; 
        _vaultView.backgroundColor = [UIColor colorWithRed:26/255.0f       green:188/255.0f blue:156/255.0f alpha:0.85f];

        UILabel *lblMySaved = [self createLabelWithTitle:@"Find all your saved   work here" frame:CGRectMake(20,115,300,60) tag:1 font:[Util Font:FontTypeLight Size:18.0] color:[UIColor whiteColor] numberOfLines:0];
    [_vaultView addSubview:lblMySaved];

     _tblVault.separatorColor = [UIColor clearColor];
     _tblVault.delegate = self;
     _tblVault.dataSource = self;
     _tblVault.scrollEnabled = NO;
        [self refreshImages];
    }

     -(void)refreshImages
    {
        [aryVaultImages removeAllObjects];


       NSArray *aryImages = [self getImagesfromDB]; // Retrieving image paths   from DB
     [_tblVault reloadData];

}
        - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
     {
      return 1;
    }

     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:     (NSInteger)section
    {

    return 2;
   }
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    return 40;

}

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
     {
    static NSString *cellIdentifier = @"Cell";
       UITableViewCell *cell = [tableView   dequeueReusableCellWithIdentifier:cellIdentifier];
     tableView.separatorColor =[UIColor clearColor];

    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    }
   if(indexPath.row ==0 && [aryImgPaths count])
   {
       NSLog(@"imagepath:%@",[aryImgPaths objectAtIndex:indexPath.row]);
       UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5,5, 40, 40)];
       [imageView setImage:[UIImage imageNamed:@"deletePost11.png"]];
       [cell.contentView sendSubviewToBack:imageView];
       [cell.contentView addSubview:imageView];

   }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return  cell;
}

【问题讨论】:

  • 你想做什么?只是显示视图?
  • 是的,我想在 uitableview 上显示视图
  • 你可以使用 _vaultView.backgroundColor = [UIColor clearColor];
  • 需要具有 RGB 值的视图背景颜色,例如 _vaultView.backgroundColor = [UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:0.85f];
  • for transparentView 用户 ClearColor

标签: ios objective-c iphone uitableview uiview


【解决方案1】:

根据我对viewController 中的视图堆栈的理解,您只需将透明视图移动到堆栈的前面(当前位于您的superView 的后面)。

你可以通过调用来做到这一点。

[self.view bringSubViewToFront:<your transparent view>];

storyboard 中只需将视图设置为正确的值

如果你想隐藏视图只需调用

[self.view bringSubViewToFront:<your tableView>];

编辑

要在UITableView 上创建一个透明视图,您需要在storyBoard 中添加一个UIView,这是您的subView 主视图subView(然后设置您想要的所有属性在属性检查器中)。您的tableView 也需要是您的viewController 主视图的subView

*确保透明视图位于storyBoardtableView 的前面

为了处理手势(因为透明视图正在“阻止”来自tableView 的手势,请阅读这篇文章Link

【讨论】:

  • 如果我添加 [self.view bringSubViewToFront:];那么 cellForRowAtIndexPath 不会被调用
  • 您可以添加您的代码吗?根据您的描述,发生这种情况是不合逻辑的
  • 您希望何时将透明视图置于顶部?从一开始?
【解决方案2】:
tableView.backgroundColor = [UIColor clearColor];
tableView.backgroundView.backgroundColor = [UIColor clearColor];

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
if ([view isKindOfClass:[UITableViewHeaderFooterView class]]) 
{
   UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView *)view;
    headerView.contentView.backgroundColor = [UIColor clearColor];
    headerView.backgroundView.backgroundColor = [UIColor clearColor];
}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    相关资源
    最近更新 更多