您好,我想在 UITableview 中显示图像,在 uitableview 之上我需要透明 View 。
我试过的是:
在 Storyboard 中添加了 View ,并在其之上添加了 UITableView。
_vaultView.backgroundColor = [UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:0.85f];
Ian 无法显示透明 View 。
请建议我如何进一步进行。
编辑:
- (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;
}
最佳答案
根据我对 viewController
中 View 堆栈的理解,您只需将透明 View 移动到堆栈的前面(它当前位于 superView
的后面)。
您可以通过调用来完成此操作。
[self.view bringSubViewToFront:<your transparent view>];
并且在 storyboard
只需将 View 设置为正确的值
如果你想隐藏 View 只需调用
[self.view bringSubViewToFront:<your tableView>];
编辑
在你身上创建一个透明 View UITableView
, 你需要添加一个 UIView
在storyBoard
那是一个subView
你的viewController
主视图(然后在属性检查器中设置你想要的所有属性)。你的tableView
还需要是 subView
你的viewController
主视图。
*确保透明 View 在tableView
的前面在你的storyBoard
为了处理手势(因为透明 View “阻挡”了来自 tableView
的手势,请阅读这篇文章 Link)
关于ios - 在具有透明 View 的 UITableview 中显示图像列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28536101/