【问题标题】:How do I make UITableViewCell's ImageView a fixed size ,Texts not aligning properly?如何使 UITableViewCell ImageView 固定大小,文本未正确对齐?
【发布时间】:2015-09-14 19:12:34
【问题描述】:

如何在 tableViewCell 中设置 imageView 的固定大小,以便文本和图像正确对齐..

我已经尝试过以下事情

     self.imageView?.frame.size.width = 40.0
     self.imageView?.frame = CGRectMake(0,0,40,40)

     cell.imageView.autoresizingMask = ( UIViewAutoresizingNone );
     self.imageView?.autoresizesSubviews = false
     cell.imageView.contentMode = UIViewContentModeCenter;
     self.imageView?.bounds = CGRectMake(0, 0, 50, 50);
     cell.imageView.frame = CGRectMake(0, 0, 50, 50);
     cell.imageView.image = [UIImage imageWithData: imageData];
     self.contentView.frame = self.bounds;

谢谢。

【问题讨论】:

  • 您可以在情节提要的单元格原型中为 imageView 添加宽度和高度约束。
  • 故事板中没有图像视图,你能告诉我如何从 uitableviewcell 类中做到吗?

标签: ios iphone swift swift2


【解决方案1】:

您可以尝试从代码中设置宽度或高度限制。

yourImageView.translatesAutoresizingMaskIntoConstraints = false
let widthContsraint = NSLayoutConstraint(item: yourImageView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100 // your_value)
let heightConstraint = NSLayoutConstraint(item: yourImageView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100 // your_value)
yourImageView.addConstraints([widthContsraint, heightConstraint])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多