airsoftFreak
airsoftFreak

Reputation: 1608

How do i add my own header on ios/swift

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?

Upvotes: 0

Views: 299

Answers (2)

Kumar KL
Kumar KL

Reputation: 15335

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

Upvotes: 1

user5938635
user5938635

Reputation:

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

Upvotes: 0

Related Questions