3.7 关于UITableView

任意设置Cell选中状态的背景色: 

UIView *bgView = [[UIView alloc]init];

bgView.backgroundColor = [UIColororangeColor];

self.selectedBackgroundView =bgView;

[bgView release];

该方法设置的是纯色, 也可以使用任何图片,把selectedBackgroundView设成UIImageView。

 

除了上面的方法,前几天发现了一个新方法:重写UITableViewCell 的 setSelected:animated:方法

-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
   if (selected) {
      self.backgroundColor = RGB(224,152, 40);
   }
   else {
      self.backgroundColor = [UIColorclearColor];
   }
}

点击Cell中的按钮时,如何取所在的Cell:

-(void)OnTouchBtnInCell:(UIButton*)btn
{
  CGPoint point = btn.center;
  point = [table convertPoint:pointfromView:btn.superview];
  NSIndexPath* indexpath = [tableindexPathForRowAtPoint:point];
  UITableViewCell *cell = [tablecellForRowAtIndexPath:indexpath];
  ...

  // 也可以通过一路取btn的父窗口取到cell,但如果cell下通过好几层subview才到btn,就要取好几次 superview

  // 所以我用上面的方法,比较通用。这种 方法也适用于其它控件。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值