Reputation: 233
let cell = tableview.dequeueReusableCell(withIdentifier: "cell1") as! viewTableViewCell
let head = titlelist[indexPath.row] as! String
cell.lbl.text = head.uppercased()
if(UIScreen.main.bounds.size.height == 1366)
{
cell.img.heightAnchor.constraint(equalToConstant: 216).isActive = true
cell.img.widthAnchor.constraint(equalToConstant: 395).isActive = true
self.view.updateConstraints()
}
I want to change the width and height constraint for my imageview img in cell.but its not updating.any help is appreciated, thanks.
Upvotes: 1
Views: 767
Reputation: 3677
Just like in below Image. Select your constraint lets say 'Width' and after select look at the left opened panel you'll see a +
button before constant
just tap on it a pop up will open with a menu like
This is for iPhone. To create another constant for iPad just change width form Compact
to Regular
Now your constraint has two constant variables. One for iPhones and one for iPads. Assign different constant values as per your requirement.
PS: You should not change Height and Width from
+
is different thing.Compact Width and Regular Height
means aniPhone
andRegular Width and Regular Height
means aniPad
Upvotes: 1
Reputation: 100503
You can try
cell.img.translatesAutoresizingMaskIntoConstraints = false
if UIDevice.current.userInterfaceIdiom == .pad {
//iPad
cell.img.heightAnchor.constraint(equalToConstant: 400).isActive = true
cell.img.widthAnchor.constraint(equalToConstant: 500).isActive = true
}
else if UIDevice.current.userInterfaceIdiom == .phone {
//iPhone
cell.img.heightAnchor.constraint(equalToConstant: 216).isActive = true
cell.img.widthAnchor.constraint(equalToConstant: 395).isActive = true
}
cell.img.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 5).isActive = true
cell.img.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: 5).isActive = true
cell.img.centerXAnchor.constraint(equalTo: cell.contentView.centerXAnchor, constant: 5).isActive = true
this requires dynamic table height
Upvotes: 3