Reputation: 599
When I use the StoryBoard, I can add an UIImageView to UITableView like this:
I am trying to write an UIScrollView extension to add a parallax image into a UITableView which can be reused for all the tables easily. Here my code to add image:
extension UIScrollView {
func addParallaxImage(image image: UIImage, height: CGFloat) {
let myImageView: UIImageView = UIImageView()
myImageView.image = image
myImageView.contentMode = UIViewContentMode.ScaleAspectFill
myImageView.frame.size.width = UIScreen.mainScreen().bounds.size.width
myImageView.frame.size.height = height
myImageView.frame.origin.y = 0
self.addSubview(myImageView)
}
}
Function usage:
tableView.addParallaxImage(image: UIImage(named: "pets")!, height: 100)
However, my image overlaps the table.
Any solutions?
Upvotes: 1
Views: 1032
Reputation: 2355
The best solution for your case is used tableview header and here the most usable libs:-
Take care not all libs support Swift, I hope I help you.
Upvotes: 1
Reputation: 2151
Instead of addSubview try using insertSubview(_ view: UIView, atIndex index: Int) with index 0, so it won't be above your cells.
Upvotes: 0
Reputation: 24
If you wanna reused the cell. You can try to add the ImageView into your tableViewCell. By the way, the header and the footer can be reused too.
Upvotes: 0