-
Notifications
You must be signed in to change notification settings - Fork 831
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
Issue when configured using auto layout and viewDidLoad #22
Comments
I believe setting the Try adding this line after line 111:
Let me know whether that fixes it or not as I wasn't able to reproduce your issue on my side, so it would be awesome if you could provide a sample project. |
I've created a test project if you want to have a look at it: https://github.com/sguillope/HMSegmentedControlTest |
Sorry it took me ages to get back to you. It has been a busy couple of weeks. Pre version 1.3, if the frame of the control wasn't set, the width would be calculated based on the number of segments and the size of the strings inside them. This wouldn't work with the case of the scroll view because if its width is equal to the total width of the segments then it wouldn't scroll. According to the AutoLayout constraints you're using, the scroll view width should be set to the width of its super view, but that doesn't happen because by the time the segmented control moves to the super view, the AutoLayout constraints wouldn't have been applied yet. The simple solution for this is to update the segmented control frame after the AutoLayout constraints have been applied:
|
I think it's better if you set the frame in
|
Actually if you set the frame in view's ``layoutSubviews` it should work (not tested).
|
Actually, according to the View Controller Programming Guide, Thanks @Mo7amedFouad! :) |
Thank you, using |
How do you see this being added to |
layoutSubviews will get called when constraints are being applied. This ensures that the frame of the scrollview and the segments will get updated accordingly. Fixes HeshamMegid#22
Hi,
Since the release of 1.3 and the introduction of the scrolling capability we're not able to use
HMSegmentedControl
in combination with auto layout's constraints.We configure our subviews in
viewDidLoad
and at that time their frame is not determined yet. We use auto layout constraints to have the subviews automatically placed properly.The problem is that when
HMSegmentedControl
sets the frame ofself.scrollView
(line 257),self.frame.size.width
andself.frame.size.height
are equal to0
making the view invisible.Here's an example of our setup:
Note:
self.containerView
is already a subview ofself.view
through the storyboardThe text was updated successfully, but these errors were encountered: