Reputation: 6931
So I have this screen:
This image is a subview of a UIView, which I use as a header for a table:
class CoursesDetailPageHeader: UITableViewHeaderFooterView {
@IBOutlet weak var imageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
func setDefaultImage() {
imageView.image = UIImage(named: "header")
}
}
And my tableView:
override func viewDidLoad() {
super.viewDidLoad()
let headerNib = UINib(nibName: "CoursesDetailPageHeader", bundle: nil)
tableView.register(headerNib, forHeaderFooterViewReuseIdentifier: "pageHeader")
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 220
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let pageHeader = tableView.dequeueReusableHeaderFooterView(withIdentifier: "pageHeader") as! CoursesDetailPageHeader
pageHeader.setDefaultImage()
return pageHeader
}
What should I do, to bring the tableView to the top, so that there is no empty space (where the transparent navController)?
UPD: To show what I want to have: Desired TableViewController
SOLVED: Thank to @kathayatnk issue was solved with the following code:
let statusBarHeight = UIApplication.shared.statusBarFrame.height
let navigationBarHeight = navigationController!.navigationBar.frame.size.height
let insets = UIEdgeInsets(top: -(statusBarHeight + navigationBarHeight), left: 0, bottom: 0, right: 0)
self.tableView.contentInset = insets
Upvotes: 0
Views: 70
Reputation: 1015
You can probably set the insets of the embedded tableView
let insets = UIEdgeInsets(top: -64.0, left: 0, bottom: 0, right: 0)
self.tableView.contentInset = insets;
Upvotes: 1
Reputation: 1906
For this you have to do UINavigationBar
Translucent
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
return true
}
Upvotes: 1