【发布时间】:2016-04-18 11:12:05
【问题描述】:
我正在尝试更改 tableView 内部的 UIView 高度。 UIView 高度不应超过单元格高度。
我试图设置view 的边界,但它没有影响视图。
我该如何解决这个问题并改变view的高度
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UIView *view=(UIView *)[cell viewWithTag:999];
view.backgroundColor=[UIColor redColor];
[view setBounds:CGRectMake(view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, 400)];
return cell;
}
【问题讨论】:
-
但背景颜色按我的预期改变了
-
您必须增加与您的视图相关的表格单元格高度。如果您使用的是自动布局,请使用布局约束。
-
你能解释一下如何访问 cellForRowAtIndexPath 中的布局约束
-
您必须在单元格内创建视图的 NSLayoutConstraint。或者你可以增加细胞的高度。并为视图提供底部约束。
-
如果要改变单元格中控件的高度,那么同时也需要改变单元格的高度。
标签: ios objective-c uitableview uiview