`UITableViewCellAccessoryCheckmark` 是图像吗? [英] Is `UITableViewCellAccessoryCheckmark` an image?

查看:13
本文介绍了`UITableViewCellAccessoryCheckmark` 是图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定义一个自定义UITableViewCell,其中UITableViewCellAccessoryCheckmark 位于UILabel 的左侧.我应该将其定义为图像还是有更聪明的方法?

I need to define a custom UITableViewCell where the UITableViewCellAccessoryCheckmark is on the left side of a UILabel. Should I define it as an image or is there a smarter way?

非常感谢,卡洛斯

推荐答案

这只是一个关于 Apple 文档.所以只需将其定义为 UIView.

It's just an UIView regarding to the Apple Documentation. So just define it as an UIView.

首先,您必须创建自己的 UITableViewCell 子类(在本例中称为 MyCell).在这个类中,在 layoutSubviews 方法中定义你的 AccessoryView 的框架.

First you have to create your own subclass of UITableViewCell (in this case it's called MyCell). In this class, define the frame of your AccessoryView in the layoutSubviews method.

- (void)layoutSubviews {
    [super layoutSubviews];
    self.accessoryView.frame = CGRectMake(0, 0, 20, 20);
}

在您的视图控制器中,告诉表格将此类用作单元格.另外,您必须将附件视图设置为包含您的图像的 UIImageView.

In your view controller, tell the table to use this class as a cell. Additionaly you have to set the accessoryView to the UIImageView containing you image.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check.png"]] autorelease];
    }
    // Configure the cell.
    return cell;
}

当用户点击一个单元格时,您可以简单地更改表格单元格的附件视图的图像.

When the user taps on a cell you can simply change the image of the accessoryView of the table cell.

这篇关于`UITableViewCellAccessoryCheckmark` 是图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆