I have a subclass of a UITableViewCell, in the cell I have a UIImageView with a content mode set to ScaleAspectFit. The UIImageView has a static height and uses equal leading & trailing constraints, it also has a top constraint.
Directly below the UIImageView, I have a UIView that I'd like the width to be equal to the width of the scaled image. Ideally I'd like to set a minimum width as well.
I seem to be having trouble getting the size of the image in the image view.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCellWithIdentifier("sampleCell") as? SampleCellTableViewCell else {
return UITableViewCell()
}
return cell
}
}
// the cell
class SampleCellTableViewCell: UITableViewCell {
@IBOutlet weak var theImage: UIImageView!
@IBOutlet weak var theView: UIView!
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
}
}
I've tried many things to this point so would like a fresh idea if you have one, thank you.