imageview如何固定宽度(例如都是320),而高度随真实图片的比例来设定

来源:互联网 发布:数据恢复软件破解版app 编辑:程序博客网 时间:2024/05/17 05:19

原来如此简单,哪 怕是读取的是网络中的图片也是这样的:

static NSString *CellIdentifier =@"Cell";

        

        CHCustomDetailCell *cell = (CHCustomDetailCell *)[tableViewDemodequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)

        {

            cell = (CHCustomDetailCell *)[[[CHCustomDetailCellalloc] initWithStyle: UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

        }

        cell.cusDetailLabel.text =@"荷叶烧肉@烤肉季 限时半价";

        

        cell.cusDetailImagView.image =nil;

        GCCDetailObject *object = [[GCCategoryDetailMgrShareInstanceSearchMgr].cdArrayobjectAtIndex:indexPath.row];

        NSURL *url = [NSURLURLWithString:object.cImage];

        if (cell.cusDetailImagView.image ==nil) {

            cell.cusDetailImagView.image = [UIImageimageWithData:[NSData dataWithContentsOfURL:url]];;     //这个即是读取的网络图片,本地图片就更不用说了

        }

      

        CGFloat hei = cell.cusDetailImagView.image.size.height;

        CGFloat wid = cell.cusDetailImagView.image.size.width;


        CGFloat zhenshi = (320 * hei / wid);

        cell.cusDetailImagView.frame =CGRectMake(0, 0,320, zhenshi);

        cell.cusDetailLabel.frame =CGRectMake(0, zhenshi - 60, 320, 60);

        [cell setFrame:CGRectMake(0,0, 320, zhenshi)];

        

        return cell;