买不来的iOS实用技巧

tableViewCell 简单使用

2015-07-26  本文已影响369人  Yanni_L

tableView的注意点

// 设置当前tableView向下偏移64
    self.userTableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
// 默认选中0组0行
[self.TableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    [self reloadData]

tableViewCell 的使用注意点

    // 设置图片
    self.imageView.image
    // 设置子标题
    self.detailTextLabel.text
    // 设置主标题
    self.textLabel.text

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    // 需要调用父类的方法
    [super setSelected:selected animated:YES];

    // 设置当前cell里面的一些属性的隐藏
    self.selectIndicator.hidden = !selected;

    // 设置字体的颜色
    self.textLabel.textColor = selected ? self.selectIndicator.backgroundColor: viewBackGroundColor(78, 78, 78);

    }

// 从新调整label的位置大小
- (void)layoutSubviews
{
     // 必须调用super 的方法
      [super layoutSubviews];

    // 更改y值
    self.textLabel.y = 2;

    // 更改高度
    self.textLabel.height = self.contentView.height - 2 * self.textLabel.y;
}

上一篇 下一篇

猜你喜欢

热点阅读