Comments (9)
Hi,
maybe you can hack it like this: compute the ideal height for one line and then, every time the content of that label changes, set the contentHeight
of the header view to be contentHeightForOneLineHeight
+ labelHeightForOneLine
- currentLabelHeight
.
from gskstretchyheaderview.
So my Xib's class calls an API to load the data into it's subviews and obviously that call is asynchronous. Which means that I might still be receiving data while the tableView.addSubview(header)
already get's executed in my viewcontroller. Prior to using this library, I was using the same Xib to load into the tableView's tableHeaderView
and once added there I would trigger a re-layout on the tableHeaderView
which would re-size everything appropriately using the label's sizeToFit()
and layoutIfNeeded()
, and it works great. However, the same approach isn't working here. GSKStretchyHeaderView
doesn't seem to be using the tableView's tableHeaderView
so can you tell me how I can access the stretchyHeaderView's view once it's added onto the tableView?
Also, will setting the maximumContentHeight
after the header is added to the tableview work? (so far it doesn't seem like it does). So even if I were to somehow calculate the label line height as you suggest, that calculation would be completely pointless if I am unable to assign it to the maximumContentHeight
. What is really needed for this to work is somehow being able to trigger another layout pass perhaps using a delegate. The other way would really be to simply remove and re-add the headerview again, but I need to test this theory.
I really want this library to work for me but all the headers in my app have dynamic content as I explain above so it's going to be really difficult to use this without ugly hacks.😥
from gskstretchyheaderview.
Hi,
well, you will need to keep a reference to the header view in the view controller or wherever. When you change the maximumContentHeight
, you may want to check if you are at the top of the table view, and then scrollToTop()
manually.
I would try experimenting with some user-triggered height change, like tapping some button that adds text synchronously to your label in order to test this approach. Once you get it to work, you may add your code reacting to asynchronous calls.
from gskstretchyheaderview.
Yes. The table is at its original position when I try to change the maximumContentHeight. I will try your suggestion in my dev environment today.
from gskstretchyheaderview.
@gskbyte so here is what I found. With a button which adds 10 pts to the maximumContentHeight
, the height gets increased but it only takes affect if I drag the tableview/scrollview down and release. I tried firing a layout pass after adding on to the maximumContentHeight
but it didn't work.
from gskstretchyheaderview.
OK I think I found something that does work (somewhat). I was able to expand the header using stretchyHeader.setMaximumContentHeight(300, resetAnimated: true)
. The 300 is just a static hard coded value but my next step is to find the custom UIView
's final height after all data has been populated.
from gskstretchyheaderview.
Alright, I give up. It won't work in this scenario, i.e. if the header view XIB has dynamic content especially in a stackview and uses autolayout. I think if we get the capability of doing tableView.tableHeaderView = stretchyHeader
instead of tableView.addSubview(stretchyHeader)
then the tableview will respect the autolayout inside of the header XIB + we can then easily trigger a layout pass and utilize setMaximumContentHeight
to resize the header (i tried assigning to tableHeaderView
but it didn't work).
With the current addSubView
method there is no way to determine the height from the XIB, the only way it could work if I set translatesAutoresizingMaskIntoConstraints
of the stretchy header to false
and then have to manually add constraints which could get very ugly very quickly. 🙁
from gskstretchyheaderview.
Well, if the only thing changing the height of the header view is the amount of text, then you can use that every time the height changes to set the maximumContentHeight manually...
from gskstretchyheaderview.
Yes that's how I finally ended up doing. Calculate the label height using the boundingRect
and then adding (or removing) the offset to the default header height using setMaximumContentHeight
. It's working perfectly.
from gskstretchyheaderview.
Related Issues (20)
- TableView does not show the header
- Scalable Text Example is incorrect for iOS 14
- GSKStretchyHeaderView fixZPositions prevents subviews in the same UIScrollView from setting differing zPositions
- HeaderView is hidden at first run of the tableView. HOT 2
- Blank headerView HOT 4
- Header Overlaps Statusbar in iOS10. HOT 4
- Can't reference GSKStretchyHeaderViewSubclass after install with Cocoa Pods HOT 11
- Header view label HOT 1
- Navbar Button issues in iPhone X HOT 1
- GSKStretchyHeaderView in Swift 4.1 with storyboad. HOT 3
- Header always collapse when set ContentInset for TableView HOT 2
- GSKStretchyHeaderView issue with insert or delete rows. HOT 1
- Redraw issue when in inactive tab HOT 5
- Refresh Control? HOT 2
- Refresh control above header?
- GSKStretchyHeaderView overlaps tableView and has no height HOT 1
- GSKStretchyHeaderView - Xamarin iOS HOT 1
- Drop shadow issue
- TableView section grouped HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gskstretchyheaderview.