自定义UITableView:核心代码就3句 - (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *TableSampleIdentifier = @"TableSampleIdentifier"; UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier: TableSampleIdentifier]; NSUInteger row = [indexPath row]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier: TableSampleIdentifier] autorelease]; } UIView *view = [[UIView alloc] initWithFrame:CGRectMake(1, 1, 45, 65)];//添加view视图 代码1 UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(250, 10, 63, 30); [btn setTitle:@">" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; [btn setBackgroundColor:[UIColor clearColor]]; [btn.titleLabel setFont:[UIFont fontWithName:@"DFPShaoNvW5" size:20.0]]; [btn.titleLabel setTextColor:[UIColor blackColor]]; [btn addTarget:self action:@selector(btn4Action:) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:btn];//在视图中加入button ; 代码2 //只要把自己要添加的控件加入到view就行了 [cell.contentView addSubview:view];//在cell中加入view视图 代码3 cell.textLabel.frame=CGRectMake(100, 10, 100, 30); cell.textLabel.text = [listarray objectAtIndex:row]; NSString *str= [NSString stringWithFormat: @"%d", row]; UIImage *image = [UIImage imageNamed:str]; cell.imageView.image = image; UIImage *highLighedImage = [UIImage imageNamed:@"1.png"]; cell.imageView.highlightedImage = highLighedImage; return cell; }
自定义UITableView:核心代码就3句
最新推荐文章于 2021-11-24 22:54:01 发布