Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use uiimageview as header title #28

Open
sariminapp opened this issue Aug 25, 2017 · 1 comment
Open

Cannot use uiimageview as header title #28

sariminapp opened this issue Aug 25, 2017 · 1 comment

Comments

@sariminapp
Copy link

I modified example data so it contains:
public var name: String public var imageURL: String public var items: [Item]

I can get imageURL string within this function:
func collapsibleTableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section].imageURL }

but when I change it to return uiimage, it cannot show any image from assets even I already put that image inside assets with same name like imageURL string.
this is my code:
private func collapsibleTableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> UIImage? { let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 20)) imageView.contentMode = .scaleAspectFit let image = UIImage(named: "\(sections[section].imageURL)") imageView.image = image return imageView.image }

How to show image within header title in section?

@EnesKaraosman
Copy link

you can use it in CollapsibleTableViewHeader class, just replace your arrowLabel with something similar to code below;

// Arrow Image View
contentView.addSubview(triangleImageView)
triangleImageView.translatesAutoresizingMaskIntoConstraints = false
// width constant
triangleImageView.widthAnchor.constraint(equalToConstant: 15).isActive = true
// aspectRatio - or you may use height constant as well
triangleImageView.heightAnchor.constraint(equalTo: triangleImageView.widthAnchor, multiplier: 1.15).isActive = true
triangleImageView.centerYAnchor.constraint(equalTo: marginGuide.centerYAnchor).isActive = true
triangleImageView.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants