尝试该方法无法实现:
cell.bankbgImageView.contentMode = UIViewContentModeCenter;
cell.bankbgImageView.frame = CGRectMake(0, 0, 50, 50);
直接在tableview中修改cell 元素的大小是无法实现的,只有通过下面的做法调整:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellid = @"BankCradCell";
BankCradCell * cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"BankCradCell" owner:self options:nil]firstObject];
}
//imagview 赋值
cell.bankbgImageView.image = [UIImage imageNamed:@"bank_ny"];
//根据屏幕高度调整图片大小
CGFloat cellHeight = 100*__kRatio;
//调整大小
CGSize itemSize = CGSizeMake(cellHeight*3.25, cellHeight);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.bankbgImageView.image drawInRect:imageRect];
cell.bankbgImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cell;
}
赶紧试试吧!