我有一个简单的自定义UITableViewCell,它的配置文件图像在左侧,标题和detailsLabel在右侧。我使用了“自动布局”约束来设置屏幕上的所有视图。但是detailsLable文本很短,个人资料图像被截断。

让我知道如何解决。我可以缩小图像,使其比标题和标签的高度之和短,但我想要大图像。

// adding subviews
contentView.addSubview(profileImageView)
contentView.addSubview(nameLabel)
contentView.addSubview(jobTitleDetailedLabel)

// constraint for the views

    profileImageView.topAnchor.constraint(equalTo:self.contentView.topAnchor,     constant:10).isActive = true
    profileImageView.leadingAnchor.constraint(equalTo:self.contentView.leadin    gAnchor, constant:10).isActive = true
profileImageView.widthAnchor.constraint(equalToConstant:50).isActive = true
profileImageView.heightAnchor.constraint(equalToConstant:50).isActive = true

    nameLabel.topAnchor.constraint(equalTo:self.contentView.topAnchor, constant:10).isActive = true
nameLabel.leadingAnchor.constraint(equalTo:self.profileImageView.trailingAnchor,  constant:10).isActive = true
nameLabel.trailingAnchor.constraint(equalTo:self.contentView.trailingAnchor).isActive = true

jobTitleDetailedLabel.topAnchor.constraint(equalTo:self.nameLabel.bottomAnchor).isActive = true
jobTitleDetailedLabel.leadingAnchor.constraint(equalTo:self.profileImageView.trailingAnchor, constant:10).isActive = true
jobTitleDetailedLabel.trailingAnchor.constraint(equalTo:self.contentView.trailingAnchor).isActive = true
jobTitleDetailedLabel.bottomAnchor.constraint(equalTo:self.contentView.bottomAnchor, constant:-10).isActive = true

最佳答案

只需将jobTitleDetailedLabel高度限制添加为greaterThanOrEqualToConstant profileImageView高度+ 10作为保证金

因为如果jobTitleDetailedLabel hight小于Image hight,它将使它成为小单元格行

self.jobTitleDetailedLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 60).isActive = true

关于ios - 个人资料图片在UITableViewCell中被截断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50235991/

10-13 02:32