gpt4 book ai didi

swift - 如何修复uitableviewcell文本标签间距

转载 作者:行者123 更新时间:2023-11-30 10:54:02 25 4
gpt4 key购买 nike

如何修复单元格的文本标签在文本和图像之间具有不同的间距如何修复此表格正在通过编码创建

class NewMessageCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}



override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}

override func layoutSubviews() {
super.layoutSubviews()
self.imageView?.frame = CGRect(x: 5, y: 10, width: 70, height: 70)
self.imageView?.clipsToBounds = true
self.textLabel?.highlightedTextColor = UIColor.blue

}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}

Table Image

最佳答案

self.imageView?.frame = CGRect(x: 5, y: 10, width: 70, height: 70)

如果你设置了 UIImageView 的边界,那么它会变得困惑。 UIImageView 将自动填充单元格的大小,因此如果您以编程方式创建 View ,则可以控制整个 View 的大小。

如果您需要将所有图像设置为新尺寸以便它们正常工作,请使用此函数(我从 this question 更新了 iOS 10:

func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
let size = image.size

let widthRatio = targetSize.width / size.width
let heightRatio = targetSize.height / size.height

// Figure out what our orientation is, and use that to form the rectangle
var newSize: CGSize
if(widthRatio > heightRatio) {
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
} else {
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
}

// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)

// Actually do the resizing to the rect using the ImageContext stuff
return UIGraphicsImageRenderer(size: newSize).image { ctx in
image.draw(in: rect)
}
}

关于swift - 如何修复uitableviewcell文本标签间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54154982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com