您的位置:首页 > 产品设计 > UI/UE

UITableView的cell一些设置

2015-11-04 14:38 411 查看
//1.cell取消选中效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;

//2.cell取消自带的下滑下效果
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//3.设置系统自带的cell右边的小箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

//4.点击后,过段时间cell自动取消选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
…………
//消除cell选择痕迹
[self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}
- (void)deselect
{
[self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES];
}

//在UITableView里面,选择了某一个cell以后,点击立刻取消该cell的选中状态,可以使用如下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//some functions
......

// 取消选中状态
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
//或者
[tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
}

5.让tableView不能滑动
_tabelView.scrollEnabled = NO;
6.让tableView不现实滑动条
_tabelView.showsVerticalScrollIndicator = NO;
7.拿到某个cell
[tableView cellForRowAtIndexPath:indexPath];
//8设置cell的背景
UIView *aView = [[UIView alloc] initWithFrame:cell.contentView.frame];
aView.backgroundColor=[UIColor colorWithHex:@"47a8ef"];
cell.selectedBackgroundView = aView;
//9.自定义cell的image大小
CGSize itemSize;

if (indexPath.row==0) {
itemSize=CGSizeMake(25, 25);
}
else if (indexPath.row==3)
{
itemSize=CGSizeMake(20, 15);
}
else
{
itemSize=CGSizeMake(20, 20);
}

UIImage*ic;

if (indexPath.row == _selectCellId) {
ic=[UIImage imageNamed:selectImageArray[indexPath.row]];
} else {
ic=[UIImage imageNamed:imageArray[indexPath.row]];
}

UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);
CGRect imageRect=CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[ic drawInRect:imageRect];
cell.imageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: