gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:58:24 25 4
gpt4 key购买 nike

假设您有一个自定义的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com