iOS UITableView3

1下拉刷新

//=================下拉刷新

  • (void)downRefresh{

    UIRefreshControl *refresh = [[UIRefreshControl alloc]init];

    [tableView addSubview:refresh];

    refresh.tintColor = [UIColor cyanColor];

    refresh.tag = 1000;

    refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@”下拉刷新” attributes:@{NSForegroundColorAttributeName:[UIColor cyanColor]}];

    [refresh addTarget:self action:@selector(refreshAct:) forControlEvents:UIControlEventValueChanged];
    }

  • (void)refreshAct:(UIRefreshControl*)refresh{

    [refresh beginRefreshing]; //开始刷新

    refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@”正在刷新” attributes:@{NSForegroundColorAttributeName:[UIColor cyanColor]}];

    [self performSelector:@selector(refreshFinish) withObject:nil afterDelay:5];
    }

  • (void)refreshFinish{

    UIRefreshControl refresh = (UIRefreshControl )[tableView viewWithTag:1000];

    refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@”刷新失败” attributes:@{NSForegroundColorAttributeName:[UIColor cyanColor]}];

    [refresh endRefreshing];//结束刷新
    }

2选中单元格的处理

显示不一样的背景 字体

//=========选中cell 背景颜色变化 文字大小 颜色变化
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIView *view = [[UIView alloc]initWithFrame:cell.bounds];

view.backgroundColor = [UIColor redColor];

cell.selectedBackgroundView = view;

//新建一个label 得到原来label的text   但他遮不住 cell选中view 的文字 但可以将其设为通明 这样就看不出来了

UILabel *label = [[UILabel alloc]initWithFrame:cell.textLabel.bounds];

label.text = cell.textLabel.text;

label.textColor = [UIColor whiteColor];

label.font = [UIFont systemFontOfSize:24];

label.backgroundColor = [UIColor redColor];

[cell.selectedBackgroundView addSubview:label];

cell.textLabel.highlightedTextColor = [UIColor clearColor];

}

//=========选中cell 背景颜色变化 颜色变化 文字大小不能改变

  • (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    UIView *view = [[UIView alloc]initWithFrame:cell.bounds];

    view.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView = view;

    cell.textLabel.highlightedTextColor = [UIColor whiteColor];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值