[英]How to add a subView to tableViewCell?
在您的“ cellForRowAtIndexPath”中進行操作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
myView.backgroundColor = [UIColor redColor];
[cell addSubview:myView];
return cell;
}
您應該將其添加為單元的子視圖。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:"MyCell" forIndexPath:indexPath];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:"MyCell"];
}
UIView *aView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[cell addSubview: aView];
aView.backgroundColor = [UIColor redColor];
return cell;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.