我想在单个UITableview中添加水平滚动和垂直滚动。UITableview中的水平和垂直scrollview ios
我想我的水平最好的,但我没有得到解决。任何人都可以请帮我在这里。
所有的解决方案,赞赏。
我想在单个UITableview中添加水平滚动和垂直滚动。UITableview中的水平和垂直scrollview ios
我想我的水平最好的,但我没有得到解决。任何人都可以请帮我在这里。
所有的解决方案,赞赏。
是您可以做到这一点.. 为此,您需要在每个单元格内添加scrollView
并调整其内容大小,以便它可以水平滚动。 让我给大家简单介绍你怎么能如果您正在使用自动版式的使用,你应该插入TableView中的内容查看的细胞一个UIScrollView,并给他们约束(.Top .Trailing .Bottom .Leading)
,所有的这些限制有constant = 0
做..
。
然后在此视图中添加其他UIView
并设置您为scrollView
设置的相同约束。这会告诉你红色的约束,表明这些约束是模棱两可的,但不用担心,只需控制从这个视图画出你的光标到滚动视图的父视图,并设置相等的宽度和相等的高度。当你完成这个请更改priority of equal width constraint from 1000 to 720
。 现在最后在上面的UIView
中添加实际内容视图,并在此视图中插入想要插入的任何内容,它可能会超出其父视图的边界。当完成添加对象时,只需像上面提到的(.Top .Trailing .Bottom .Leading)
那样使用相同的常量,但是这次也应该提供宽度约束。
此宽度约束将实际上充当约束高度。您可以稍后更改大小,将此宽度约束设置为IBOutLet,然后以编程方式调整scrollContent宽度。
良好做法,你应该为你的TableViewCell
在每个单元是可以添加滚动一个CustomClass
。
您需要创建自定义单元格与UICollectionView里面放委托,数据源从您的控制器。
然后在控制器中执行UICollectionViewDelegate,UICollectionViewDatasource方法。 要识别当前显示的单元类中的哪个单元格正在创建属性,例如tableViewIndexPath您可以在中设置tableView willDisplay单元格。 我觉得它对你有所帮助。
这将作为您的requirements.Please试试这个。
#pragma mark -- Table view delegate and datasource --
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellid = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
self.tblHistory.showsHorizontalScrollIndicator = NO;
self.tblHistory.showsVerticalScrollIndicator = NO;
if (indexPath.row == 0) {
UIScrollView *scrollViewFood = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 44)];
scrollViewFood.pagingEnabled = YES;
UILabel *lblFood;
NSInteger numberOfFoods = arrFoods.count;
CGFloat xOrigin = 0;
for (int i = 0; i < numberOfFoods; i++) {
NSString *strNames = [arrFoods objectAtIndex:i];
CGSize textSize=[strNames sizeWithAttributes:
@{NSFontAttributeName: [UIFont boldSystemFontOfSize:14.0]}];
xOrigin = CGRectGetMaxX(lblFood.frame);
lblFood = [[UILabel alloc] initWithFrame:CGRectMake(xOrigin, 0, textSize.width + 10, 44)];
lblFood.text = strNames;
lblFood.font = [UIFont boldSystemFontOfSize:14.0];
lblFood.textAlignment = NSTextAlignmentCenter;
lblFood.backgroundColor = [UIColor clearColor];
[scrollViewFood addSubview:lblFood];
}
scrollViewFood.contentSize = CGSizeMake(lblFood.frame.size.width + xOrigin + 10,44);
scrollViewFood.showsHorizontalScrollIndicator = NO;
scrollViewFood.showsVerticalScrollIndicator = NO;
scrollViewFood.delegate=self ;
[cell.contentView addSubview:scrollViewFood];
}else if (indexPath.row == 2){
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 44)];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(cell.frame.size.width , 100);
[cell.contentView addSubview:scrollView];
}
return cell;
}
您根据需要更改标签的高度,宽度。
它是否适合你? – Sanjukta
对于UITableView中更好地理解滚动,你可以按照这个两个环节
我希望它可以帮助你更好地了解并熟悉的UITableViewDelegate。
您需要通过创建一个自定义的scrollView并将其放在下面的代码中。在Storyboard或其他方面,使用这个自定义的scrollView类。然后TableView和Scroll View将同时滚动。您需要这样做,因为ScrollView的gestureRecognizer委托不能从您的ViewController访问,它必须从ScrollView类本身通过继承它的子类获得。
- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
我尽我最好的水平,但我没有得到解决方案。你可以显示代码 –
我的代码是完全错误的,我删除它。你有什么建议吗? –
tableViewCell的第1行根据您的需要采取另一个集合视图或TableView。主tableView有垂直滚动和你的收藏/ tableview滚动水平.. –