简体   繁体   English

是否可以重新定位和调整标准UITableViewCell的UIImageView的大小

[英]Is it possible reposition and resize UIImageView of a standard UITableViewCell

Now I know that the UITableViewCell by default have a imageView however I tried sizing the size of it and the origin, but it won't do it. 现在,我知道默认情况下,UITableViewCell具有一个imageView,但是我尝试调整其大小和原点大小,但是不会这样做。 Do I have to subclass a UITableViewCell just to do this? 为此,我是否必须将UITableViewCell子类化?

If you want to change the default style of table view cell, you'd better subclass one, you can change it's image view's frame easily by layoutSubviews method, just like this: 如果要更改表格视图单元格的默认样式,最好将其子类化,可以通过layoutSubviews方法轻松更改其图像视图的框架,如下所示:

@implementation CustomTableViewCell

//...

- (void)layoutSubviews {
  [super layoutSubviews];

  // ...
  CGRect imageViewFrame = CGRectMake(...);
  [self.imageView setFrame:imageViewFrame];

  // you can also modify the frame or position for textLabel, detailTextLabel, etc.
}

@end

最好的选择是创建一个自定义UITableViewCell

简单的方法是将UIImageView添加到cell.contentview

UIImageView *myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(100, 5, 30, 30)];
myImageview.image = [UIImage imageNamed:@"image.png"];
[cell.contentView  addSubview:myImageview];
[myImageview release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM