我正在通過採取動手方式教授自己斯威夫特。我有一個簡單的圖像,其高度限制在故事板中設置爲150。不過,我想以編程方式將其更改爲70。如何以編程方式更改UIImageView的高度?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tableElement = tableView.dequeueReusableCell(withIdentifier: "FirstTable", for: indexPath)
tableElement.BigImage.image = ??
return tableElement
}
我做tableElement.BigImage.image
訪問圖像,我想找到它的高度屬性並將其設置爲70。我已經試過這tableElement.BigImage.image.topCapHeight = 70
不過是給出了一個錯誤。我怎樣才能做到這一點?
這是我的出路吧
class myNewCell: UITableViewCell {
@IBOutlet weak var BigImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我想學習如何改變圖像的高度編程,因爲我得到的圖像的2個不同批次的,我想他們的高度排序的分離紅色/藍色的東西。
創建的ImageView的身高約束出口,改變約束常數70。同樣,你正在試圖改變形象,而不是ImageView的 –
的高度約束@ New16你不能讓動態細胞的任一網點。 – Lumialxk
@Lumialxk OP可以出口到'UITableViewCell'爲'UIImageView'的高度約束,並相應地更新它'cellForRow' – Rikh