Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带有可选图像的自定义UITableViewCell_Ios_Xcode_Uitableview - Fatal编程技术网

Ios 带有可选图像的自定义UITableViewCell

Ios 带有可选图像的自定义UITableViewCell,ios,xcode,uitableview,Ios,Xcode,Uitableview,我有一个自定义的UITableView单元格,其顶部有一个大小与单元格宽度相当的UIImageView,下面有一个UILabel UITableViewCell具有imageView属性。如果设置了图像视图的图像,则它会向右推动单元格textlab,以容纳图像。我想对我的表视图单元格做一些类似的事情(除了我的标签会被向下推) 如何实现这一点?一种简单的方法是将UITableViewCell子类化并重写layoutSubviews方法 这里有一个简单的例子 @interface CustomCel

我有一个自定义的
UITableView
单元格,其顶部有一个大小与单元格宽度相当的
UIImageView
,下面有一个
UILabel

UITableViewCell
具有
imageView
属性。如果设置了图像视图的图像,则它会向右推动单元格
textlab
,以容纳图像。我想对我的表视图单元格做一些类似的事情(除了我的标签会被向下推)


如何实现这一点?

一种简单的方法是将
UITableViewCell
子类化并重写
layoutSubviews
方法

这里有一个简单的例子

@interface CustomCell : UITableViewCell

@end

@implementation CustomCell

- (void)layoutSubviews
{
   [super layoutSubviews];

   // grab bound for contentView
   CGRect contentViewBound = self.contentView.bounds;

   if(self.imageView.image) {
      // do stuff here, for example put the image right...
      CGRect imageViewFrame = self.imageView.frame;
      // change x position
      imageViewFrame.postion.x = contentViewBound.size.width - imageViewFrame.size.width;
      // assign the new frame
      self.imageView.frame = imageViewFrame;
   }

   else {
      // do stuff here
   }
}
特别是在该方法中,您可以根据
图像
定位单元格的组件


希望能有所帮助。

是的,我只是在尝试这方面的一些东西,很高兴能得到一些保证,我走上了正确的道路。谢谢