if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDetailButton;
        cell.textLabel.font = [UIFont systemFontOfSize:19.0];
        
        UIImage *image = [UIImage imageNamed:@"england"];
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = CGRectMake(0.0,0.0,15,15);
        button.frame = frame;
        [button setBackgroundImage:image forState:UIControlStateNormal];
        button.backgroundColor = [UIColor clearColor];
        cell.accessoryView = button;
         [button addTarget:self action:@selector(btnClicked:event:) forControlEvents:UIControlEventTouchUpInside];
    }
- (void)btnClicked:(id)sender event:(id)event
{
    NSSet * touches = [event allTouches];
    UITouch * touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.countriesTableView];
    NSIndexPath * indexPath = [self.countriesTableView indexPathForRowAtPoint:currentTouchPosition];
    if(indexPath != nil)
    {
        [self tableView:self.countriesTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
    }
}

设置imageView大小

    cell.imageView.image = [MainTableViewController scale:item.flag toSize:CGSizeMake(115, 75)];
+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage * scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

 

相关文章:

  • 2021-11-20
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-06-04
  • 2021-05-15
相关资源
相似解决方案