UITableViewCell中设置不同图片尺寸相同以及设置图片为圆形的方法
2015-10-05 16:19
776 查看
一、UITableViewCell中设置不同图片尺寸相同
// 图片尺寸不一样
修改cell左侧显示图片大小的方法 UIGraphics---
二、UITableViewCell中设置图片为圆形的方法
本人暂时没有找到其他的方法,现在用的自定义cell 来实现的,有朋友知道的话可以交流下
示例图片:图一为设置不同尺寸的图片为相同的尺寸,图二为自定义cell,使得image为圆形,似QQ界面
// 图片尺寸不一样
修改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界面
相关文章推荐
- ./configure -build,-host,-target设置
- hdu 1005 -- Number Sequence
- Java多线程15:Queue、BlockingQueue以及利用BlockingQueue实现生产者/消费者模型
- UITapGestureRecognizer 的用法
- UNIX环境高级编程中的apue.h头文件的问题
- UI_三个UITableView的省市区联动
- UITableView
- UVA_540: Team Queue
- break 和 return 和 continue
- mininet error: Cannot find required executable ovs-controller.
- HDU 5496(Beauty of Sequence-DP)
- poj 3566 Building for UN(为联合国而建)
- gFStu的UI控件
- POJ 3566 (弱校联萌十一大决战之厉兵秣马 B. Building for UN)
- u3d零基础学习之2d游戏学习笔记
- quicklisp 如何卸载本地项目
- 自定义UITableView每组头部控件
- FloatingActionButton,TextInputLayout,Snackbar,TabLayout 四种控件
- AndroidUI的组成部分ProgressBar
- tableviewcell中的badged TDBadgedCell 的实现