如何在cell里添加一个UIIMageview然后在里面添加一张图片

iOS 码拜 9年前 (2015-05-01) 765次浏览 0个评论
 

如何在cell里添加一个UIIMageview然后在里面添加一张图片如何在cell里添加一个UIIMageview然后在里面添加一张图片
在cell里面添加uiimageview image view 控件还缺少什么代码
还有在uiimage里为什么没有传图片名字的方法 imagenamed

如何在cell里添加一个UIIMageview然后在里面添加一张图片
10分
额,你那个难道不是写错了?
_imageView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,50,50)];
UITableView  这个是几个意思?

应该自定义一个UITableCell ,然后在cell的init……..里面:

UIImageView  *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[imageView setImage:[UIImage imageNamed:@”1.jpeg”]];
[self.contentView addSubView:imageView];

如果需要访问这个UIImageView的话,可以设置成property

如何在cell里添加一个UIIMageview然后在里面添加一张图片
20分
出错的地方太明显了。
_imageView 变量的类型应该是UIImageView ,你在实例这个对象的时候,给它赋的却是UITableView.问题代码:

_imageView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,50,50)];

结合你第二张图,在CellForRowAtIndex中应该这样:

BabyReadBean *bean = _mutarryDataList[indexPath.row];
UIImage *img = [UIImage imageNamed:bean.strLogo];
UIImageView *imgView =[[UIImageView alloc] initWithImage:img];
imgView.frame = CGRectMake(0,0, img.size.width,img.size.height);
[cell.contentView addSubview:imgView];

这里有一些个人建议:
使用code的方式来创建控件与布局不是不可以,但在适配其它设备时就会非常困难。我的建议是使用.xib结合autolayout来布局自定义cell, 这样不仅可以便于cell的复用,而且在适配其它设备时也很容易。

如何在cell里添加一个UIIMageview然后在里面添加一张图片
10分
我给你传一个资源:
http://download.csdn.net/detail/zhangao0086/8531019
Big Nerd Ranch iOS 第四版原版。Big Nerd Ranch在iOS培训界还是有一定的知名度的,出书的质量也高,看完想不成大师都难

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何在cell里添加一个UIIMageview然后在里面添加一张图片
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!