固定cell.imageView.image的大小
2024-10-18 18:16:09
cell.imageView.image的大小 会随着Cell的高度而变化,不同的图片显示的也不一样,在网上找了几种方法,简单方便的是下面这种:
UIImage *icon = [UIImage imageWithName:@
"xxxxx"
];
CGSize itemSize = CGSizeMake(30, 30);
UIGraphicsBeginImageContextWithOptions(itemSize,
NO
,0.0);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[icon drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
另外还有其它方法没有成功:设置cell.imageView.contentMode的属性,
还有一种是网上转载的比较多的一种,由于不是自定义的cell,没用到此方法 :
重定义一个uitableviewcell,它自动生成的代码不需要动,只要在.m文件中再加上下面的代码即可:
(具体可参看:http://blog.csdn.net/zhangjie1989/article/details/7550990)
- (void)layoutSubviews {
[superlayoutSubviews];
self.imageView.bounds =CGRectMake(0,0,44,44);
self.imageView.frame =CGRectMake(0,0,44,44);
self.imageView.contentMode =UIViewContentModeScaleAspectFit;
CGRect tmpFrame = self.textLabel.frame;
tmpFrame.origin.x = 46;
self.textLabel.frame = tmpFrame;
tmpFrame = self.detailTextLabel.frame;
tmpFrame.origin.x = 46;
self.detailTextLabel.frame = tmpFrame;
}
还有一种最直接 的方法 就是自定义一个cell。
最新文章
- 记一次Redis被攻击的事件
- 关于在用curl函数post网页数据时,遇上表单提交 type为submit 类型而且没有name和id时可能遇到的问题及其解决方法
- Redis学习笔记1-Redis的介绍和认识
- HDU 4314 Save the dwarfs (DP) ---转载
- BZOJ2159 : Crash 的文明世界
- OpenWRT 路由配置技巧
- android圆角View实现及不同版本这间的兼容
- C#中两个时间的比较
- php_cawler_html嵌套标签清洗
- Python——Python+Pydev出现SyntaxError: Non-UTF-8 code
- django-celery配置
- Ionic3多个自定义过滤器--管道(pipe)
- 201901<;<;叶武滨时间管理100讲>;>;
- IPv6地址测试宏
- Java 深复制和浅复制
- ARM Linux Oops使用小结(转)
- 《DSP using MATLAB》Problem5.23
- springboot 设置 session 过期时间
- 虚拟机中安装Ubuntu 16.04
- How To Open An URL In Android’s Web Browser