ios - 在 UITableViewCell 中修改 UIView 外观的正确方法是什么?

标签 ios objective-c uitableview uiview

假设您有一个自定义的 UITableViewCell,并且在单元格中有一个 UIView,您希望其中有一个右下角和右上角的半径。进行这些更改的正确位置在哪里?

我假设它不在 UITableViewCell 的 drawRect 中,因为那将是一个巨大的性能损失。 UITableViewCell 中是否有其他函数可以执行此操作?或者我应该在函数中的 UITableViewController 中执行此操作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

最佳答案

一旦您在 cellForRowAtIndexPath 中实例化您的自定义单元格,我就会这样做:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

NSString *cellIdentifier = @"cell";
UICustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     cell.customview.layer.cornerRadius = 5.0f;
    //add other custom stuff here as well
}

return cell;
}

关于ios - 在 UITableViewCell 中修改 UIView 外观的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595877/

相关文章:

ios - 用什么方法将 NSString 价格乘以数量? ios

ios - Apple Itunes App Rejection 由于背景模式位置

objective-c - 如何在 Swift 中创建立即调用的函数( block )

iphone - 如何复制 CALayer?

ios - UITableView:我想使用一种可以轻松修改部分和行(添加、删除)的方法。

ipad - 可以在不重新加载表格 View 的情况下更改 UITableViewCell 的高度吗?

ios - 适当的 ReactiveCocoa 链接

ios - 将 Float 数组写入二进制文件并快速读取

ios - 将 Datetime c# 转换为 Objective c 和反转

ios - 拖动单元格时如何在 UITableViewCell 中隐藏阴影