UITableViewCell中设置不同图片尺寸相同以及设置图片为圆形的方法

来源:互联网 发布:vx软件 编辑:程序博客网 时间:2024/06/12 14:47

一、UITableViewCell中设置不同图片尺寸相同

//    图片尺寸不一样 修改cell左侧显示图片大小的方法  UIGraphics---

<span style="font-size:14px;font-family: KaiTi_GB2312; color: rgb(204, 153, 51);">   </span><span style="font-size:18px;color:#333333;font-family: SimSun;"> </span><span style="font-family:System;font-size:14px;color:#333333;">UIImage *icon = [UIImage imageNamed:[NSString stringWithFormat:@"%@", model.singerHeaderName]];;    CGSize itemSize = CGSizeMake(70, 70);    UIGraphicsBeginImageContext(itemSize);    CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);    [icon drawInRect:imageRect];        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();</span>


二、UITableViewCell中设置图片为圆形的方法
本人暂时没有找到其他的方法,现在用的自定义cell 来实现的,有朋友知道的话可以交流下

<span style="font-size:14px;">- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {                self.iv = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 40, 40)];        self.iv.backgroundColor = [UIColor clearColor];        self.iv.layer.cornerRadius = CGRectGetWidth(self.iv.frame)/2;        self.iv.layer.masksToBounds = YES;        [self.contentView addSubview:self.iv];                UIImage *image = [[UIImage alloc]init];        self.iv.image = image;                self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.iv.frame)+5, 5, CGRectGetWidth([UIScreen mainScreen].bounds)-CGRectGetMaxX(self.iv.frame)-5, 15)];        self.nameLabel.backgroundColor = [UIColor clearColor];        self.nameLabel.font = [UIFont systemFontOfSize:15];        [self.contentView addSubview:self.nameLabel];                self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.iv.frame)+5, 25, CGRectGetWidth([UIScreen mainScreen].bounds)-CGRectGetMaxX(self.iv.frame)-5, 15)];        self.titleLabel.backgroundColor = [UIColor clearColor];         self.titleLabel.font = [UIFont systemFontOfSize:15];        [self.contentView addSubview:self.titleLabel];    }    return self;}</span>


示例图片:图一为设置不同尺寸的图片为相同的尺寸,图二为自定义cell,使得image为圆形,似QQ界面




0 0
原创粉丝点击