自定义的tableViewCell怎样固定imageView的大小位置
来源:互联网 发布:地下城网络中断啥毛病 编辑:程序博客网 时间:2024/05/23 07:24
我拉一个自定义cell时,下载的照片老是充满cell,自定义imageView的大小也不管用,因为图片的大小是无法固定的:
解决办法:
1、在本地找一张图片加载上去,在下载后替换;
2、重加载layoutSuperViews
(1)
@implementation More_ViewController
-(void)layoutSubviews{
UIImage * img = self.imageView.image;
self.imageView.image = [UIImageimageNamed:@"1.png"];
[superlayoutSubviews];
self.imageView.image = img;
self.imageView.frame =CGRectMake(10,30, 200, 150);
}
@end
(2)网上的很多页面其实就是这种展示结果,通常需要 imageView , textLabel , detailTextlabel ,而 UITableViewCell本身提供了方便的自动布局(当有图片和没图片时,textLabel和detailLabel的位置会左右自动调整).但是图片的大小却是没有办法固定的(直接设置 imageView.frame是无法固定 imageView的大小的),那么一般来说解决这个问题的办法有两种:
固定显示图片的大小(包括PlaceHolder)
自定义tableViewCell,添加自定义的 imageView , textLabel和 detailTextLabel
这两种方式都可以解决这个问题,但是这两种方式其实都挺麻烦的,能否直接固定imageView的大小呢?方法是有的,只需要重载 layoutSubviews即可
派生UITableViewCell
//自定义一个Cell
@interface MMCell : UITableViewCell
@end
@implementation MMCell
//重载layoutSubviews
- (void)layoutSubviews
{
UIImage *img = self.imageView.image;
self.imageView.image = [UIImage imageName:@"res/PlaceHolder.png"];
[super layoutSubviews];
self.imageView.image = img;
}
@end
这样,我们只要使用 MMCell就可以固定 imageView的大小了,且大小为 PlaceHolder.png的大小(一般来说这种页面都会使用一个 PlaceHolder.png来显示默认图片).
原理是在 UItableVeiw 的 layoutSubviews 调用时,会根据 imageView.image的大小来调整 imageView , textLabel , detailTextLabel的位置,在此之前我们先将 imageView.image设置为 PlaceHolder.png图片,等待重新布局完后再将原本的图片设置回去就可以了
- 自定义的tableViewCell怎样固定imageView的大小位置
- tableViewCell调整其中自带的imageView的大小
- 固定cell.imageView.image的大小
- 固定cell.imageView.image的大小
- 固定cell.imageView.image的大小
- 固定cell.imageView.image的大小
- 长宽比固定的自定义imageview
- 获取collectionViewcCell及tableViewCell在当前屏幕的位置大小
- 自定义TableViewCell的使用方法
- TableViewCell组件的自定义
- 自定义TableviewCell的UIMenuController
- 关于tableViewCell imageView加圆角的实现
- Android 自定义imageview图片高度固定大小宽度按比例自适应
- Android 自定义imageview 图片宽度固定大小高度按比例自适应
- Android 自定义imageview 图片高度固定大小宽度按比例自适应
- 自定义按钮的 imageView 和 titleLabel 的位置
- 控制自定义Dialog的大小和位置
- DialogFragment自定义dialog的位置和大小
- 常用API(StringBuffer类和正则表达式以及常用的一些类)
- IOS-六种手势的简单使用
- 持续集成之路——搭建Maven私服 .
- matlab安装问题
- Ubuntu 下如何设置 Java 环境变量
- 自定义的tableViewCell怎样固定imageView的大小位置
- Static关键字
- Objective-C Runtime 运行时之四:Method Swizzling
- NSDate的简单总结
- 服务器端发送UDP数据包客户端未收到问题解决
- 仿QQ对话框
- 生成pci设备树的简单实现
- 网络七层架构
- HDOJ 2896 病毒侵袭