0

Im trying to add this particular header to my iphone app which lives in UIViewController

The current implementation

enter image description here

the restaurant header.enter image description here

What I want to achieve

The only solution that I could think of to add this particular header is using image view in object library

How do i do add it?

airsoftFreak
  • 1,450
  • 5
  • 34
  • 64
  • 2
    Question is unclear! You want to add header? Where? In UITableView? UICollectionView? UIView? Where? – Ashish Kakkad May 17 '16 at 06:35
  • For tableView, you can work with Xib custom headers, look at this topic here http://stackoverflow.com/questions/36926612/swift-how-creating-custom-viewforheaderinsection-using-a-xib-file – iamburak May 17 '16 at 07:01

2 Answers2

1

Use the viewForHeaderInSection delegate method to customise table section headerView

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
}

and don't forget to implement the method.

func tableView(_ tableView: UITableView,
heightForHeaderInSection section: Int) -> CGFloat
Surjeet Rajput
  • 1,251
  • 17
  • 24
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
0

Try this code it works

set the section header height in the viewDidLoad

self.tableView.sectionHeaderHeight = your desired height(in int)

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 18))
    let imageview = UIImageView(frame: CGRect(x: 20, y: 20, width: 50, height: 50))

    self.view.addSubview(imageview)

    return view
}

set images in your imageview according to your requirements