Ios 使用trasparent视图在UITableview中显示图像列表
您好,我想在UITableview中显示图像,在UITableview顶部我需要透明视图 我尝试的是: 在情节提要中添加了视图,并在其顶部添加了UITableViewIos 使用trasparent视图在UITableview中显示图像列表,ios,objective-c,iphone,uitableview,uiview,Ios,Objective C,Iphone,Uitableview,Uiview,您好,我想在UITableview中显示图像,在UITableview顶部我需要透明视图 我尝试的是: 在情节提要中添加了视图,并在其顶部添加了UITableView _vaultView.backgroundColor = [UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:0.85f]; Ian无法显示透明视图 请告诉我如何进一步进行 编辑: - (void)viewDidLoad {
_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;
}
根据我对
viewController
中视图堆栈的理解,您只需将透明视图移动到堆栈的前面(它当前位于superView
的后面)
你可以打电话来
[self.view bringSubViewToFront:<your transparent view>];
编辑
要在UITableView
上方创建透明视图,需要在storyBoard
中添加一个UIView
,它是viewController
主视图的子视图(然后在属性检查器中设置所有需要的属性)。您的tableView
还需要是viewController
主视图的子视图
*确保透明视图位于情节提要中表格视图的前面
为了处理手势(因为透明视图正在“阻止”来自表视图的手势
阅读本文)您想做什么?只显示视图?是的,我想在UITableView的顶部显示视图您可以使用_vaultView.backgroundColor=[UIColor clearColor];需要使用RGB值查看背景色,如_vaultView.backgroundColor=[UIColor color with red:26/255.0f green:188/255.0f blue:156/255.0f alpha:0.85f];对于透明视图用户clearcolor,如果我添加[self.view bringsubview tofront:];那么cellForRowAtIndexPath没有被调用您可以添加代码吗?从你描述的情况来看,什么时候你希望你的透明视图处于顶部是不符合逻辑的?从一开始?
[self.view bringSubViewToFront:<your tableView>];
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];
}
}