Iphone 表视图单元格中的图像视图框
我已将图像添加到iOS应用程序的资源文件夹中。我想将该图像添加到我的Iphone 表视图单元格中的图像视图框,iphone,ios,image,uitableview,Iphone,Ios,Image,Uitableview,我已将图像添加到iOS应用程序的资源文件夹中。我想将该图像添加到我的UITableView的每个单元格中。我调整单元格中图像的大小,如下图所示: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell.imageView.frame=CGRectMake(10, 27, 30, 30); } 但我的图像显示的大小类似于资
UITableView
的每个单元格中。我调整单元格中图像的大小,如下图所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell.imageView.frame=CGRectMake(10, 27, 30, 30);
}
但我的图像显示的大小类似于资源文件图像,但我希望它位于上面提到的帧
我的研究给了我这样的想法:
-(void)layoutsubviews
{
cell.imageView.frame=CGRectMake(10, 27, 30, 30);
}
如何使用它?您是否尝试过[cell.imageView setContentMode:UIViewContentModeAspectFit]代码>?您是否尝试过[cell.imageView setContentMode:UIViewContentModeAspectFit]代码>?试试这个
-(void)layoutsubviews
{
self.imageView.frame=CGRectMake(10, 27, 30, 30);
}
我不确定编译器是如何允许您访问-layoutSubviews
方法中的单元格的。简而言之,在此处设置的任何帧都将覆盖UITableViewCell的默认帧 试试这个
-(void)layoutsubviews
{
self.imageView.frame=CGRectMake(10, 27, 30, 30);
}
我不确定编译器是如何允许您访问-layoutSubviews
方法中的单元格的。简而言之,在此处设置的任何帧都将覆盖UITableViewCell的默认帧 只需在设置图像之前调用这行代码。您不必知道“LayoutSubview”是如何实现您所说的功能的,抱歉,我刚刚通过研究找到了它。-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{[cell.imageView setContentMode:UIViewContentModeAspectFit];[cell.imageView setImage:yourImage];}在设置图像之前,只需调用这行代码。您不必知道“LayoutSubview”是如何完成您所说的内容的,或者我刚刚通过研究找到了它。-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*))indexPath{[cell.imageView setContentMode:UIViewContentModeAspectFit];[cell.imageView setImage:yourImage];}