MarqueeLabel text won't scroll - ios

I want to display a label that continuously scrolls horizontally if it doesn't fit its superview. Kind of like on television when you have info showing up at the bottom with scrolling text.
I use MarqueeLabel/Swift pod
I created a sample project with a simple label that doesn't fit its superview:
I set its class as a MarqueeLabel:
I added some settings just as shown in their demo project:
And finally added this in code, same thing, I copied/pasted it from their demo (sorry for the image this time I couldn't get the formatting to work on stack-overflow!):
Any suggestion ? My only doubt is that when I set the class to be a MarqueeLabel, it automatically sets the Module as "MarqueeLabel" whereas I would have expected it to name it after my project name : "TestMarquee"

The problem maybe is the fact that your label view is out of the visual bounds of the parent view, thus you might need to add constraints to it.
I suggest you limit the label with 10-10 constraints on the left and right side respectively, and center it horizontally and vertically.
This way, the parent view controller will be able to layout it properly for you.

Related

Right-alignment constraints?

I'm trying to add constraints to right-align a button to its parent view, but having some problems. In the following image, I've created left-aligned constraints for the < button. The Play button is center aligned, independent of the < button.
I've tried adding a constraint for the Reload button to be right aligned, but it sets a fixed distance which doesn't align but rather creates a fixed position. Not sure what I'm missing here.
I've updated this question with an image of the existing constraints.
Have you been using "Trailing Space to Container"? If this doesn't work you will need to check:
Which view is the container of your Reload button to ensure it isn't aligning with the wrong view
That the container view has the bounds you expect it to have
If you need further help, could you please upload your view hierarchy, like so:
Also the existing contraints on the reload button would be helpful so we can eliminate any interaction between constraints :)

Stack View example from the book "Beginning iOS 9 Programming with Swift"

So I was following the textbook instruction (beginning ios 9 programming with swift) from Chapter 6 to learn Stack View in Swift. However, I can't get the example to work. The image is just not displayed correctly in any version of simulator. So this is a vertical stack view with two constraints, "vertical spacing to top layout guide" and "center horizontally in container".
Any suggestions or similar problems that got solved?
Thanks!
Below are the wrong and right images:
First, get your wardRobe label with this setting, I set the Font size to 40, you can customize the way you want.
Second, get the other label like so :
Again, you can customize the settings of the label
Next, set the width of the two to be the same so that it looks like this:
Awesome, time for introducing player of the game, The Stack View:
Click on the button in your main storyboard (see below)
Next, click one of your labels and hold command, then select the other label too. (Both labels should be selected together). Next, click on this button in your storyboard:
Your stack view should look something like this :
Now, to resize the image, tick select the width and height and type in the desired values, and click add constraint:
Now, go to your view hierarchy and click add missing constraints, and you are done!
It should say, no layout issues like so
Update: Resolving auto lay out across different configurations:
Select your stackView like so:
Next, tick Horizontally in container and then add 1 constraint
Finally, go to view hierarchy and click fix misplacement. That should sort everything
Final preview

Auto Layout: Displaying content relative to container

I'm having some issues developing an iPhone application. I have a UITableView on a screen and have made a template for how I want to lay things out. I made sure that the constraints are satisfied and when my program compiles, I get no auto layout issues. However, when I run my program on the simulator, some of the text is not shown but I know it should be there. Here is how things look on the Storyboard:
However, this is how things look when I run the program on the iPhone simulator, it appears as so:
I am only worried about the From Date and To Date fields not being displayed because if I move them more to the left, I can eventually see them. Moreover, I made sure to make the To Date field's Trailing Space to Container Marginby 8 px so I don't really understand why these two fields aren't showing. Any help would be appreciated. Thanks!
Edit: Image of To Date constraints:
Edit 2: Image of how table view cell looks like now:
Most likely the labels are not showing because of size classes and the difference between the different screen sizes. In your story board the original view controller is a square shape. Make sure to pin the labels to the side of the cell that you want them to attach to. This will make sure they stay where you want them to. Also make sure that you pin the actual table view to the superview so you can see the labels. I have always pinned to the top, bottom, and both sides, to accommodate different screen sizes and rotation. You may need to change the constraints for the other size classes. This may make some things look they are bunched up a bit with the smaller screen size, but you can always change the font or the format of the cell to fit everything in.
If you want to change a constraint for another size class, just select that size class at the bottom of the story board. Select the label, and then in the size inspector you can make the constraints you don't want to be unable, and hook up some other constraints to make it work. Ray Wenderlich's web site has a great tutorial on size classes and adaptive layout. You can find it here.
Happy coding!!
Your "missing" labels are probably too far to the right, outside the screen boundaries. This could happen if your view controller is wider in the storyboard than when you run it. Make sure that your labels have constraints for trailing space -- that will cause them to always be within the screen bounds no matter the screen width.
Also, use the Debug View Hierarchy in Xcode to see where those labels actually end up.
UPDATE:
Try overriding awakeFromNib method in your UITableViewCell subclass:
override func awakeFromNib()
{
contentView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
}

Fill UIScrollView with its content using autolayout in iOS

I am making a form based UIScrollView, which will contain some labels and text fields.
My ScrollView Height will increase as per the iOS device height.
PS: I do not want to add constraint to each and every element of the Scrollview, because in my case there could be 100 form fields.
What I want is, the inner content to fully occupy my scrollView like this:
Till now there a are no special constraints, the button is tagged with the bottom edge and the scroll view is pinned from the top edge. Also, the vertical spacing between scrollview and button is defined.
This is the autolayout constraint screenshot.
If the number of labels is variable, I recommend doing them in code, rather than in Interface Builder.
In code, you can use a loop to set every label to have the same width/height as the one above it. You may want to set their height to be >= a minimum value. Be sure to anchor the first label with the top, and the last label with the bottom.
But this can be cumbersome, why not just use a UITableView? you may modify the row height to let the cell fully occupy the view.
- tableView:heightForRowAtIndexPath:
- tableView:estimatedHeightForRowAtIndexPath:
I just face the same issue and already write a pod called TLFormView that do exactly that: a form based on UIScrollView.
It also has some nice features like:
declarative form taxonomy with TLFormModel Just extend it, add the properties you want and that's it. No delegate, no event handling, no boilerplate.
a nice way to handle different layouts for iPhone and iPad
conditional visibility with an NSPredicate that can access all the values in the other fields (e.g: show field A when field B has certain value)
in place help with a popover
all the fields are TLFormFields that extend UIView so you can place whatever you need.
You can try it right from the command line with pod try TLFormView.
If you want to know more I wrote some blog post about it here.
Please let me know your thoughts about it here or as a comment in the blog posts. Also any contribution is extremely welcome in the GitHub repo

Popover not showing the content

I'm just trying to display a ViewController as a Popover, this is a small part of a big iPad application, and I've being trying to display the content with no success.
The worst thing is that if I create the same scenario in an empty/new project, it's works! The two View Controllers showed in the Image1 are completely new, I created those after tried to add a simple Popover action in one of my views I'm using in the App...which was not working. I tried with Clean and Build the Project more than once...just in case, but the same result. It's just not working in this specific project.
The two view controllers don't have Classes associated yet, I'm just trying to open the View2 when I click on the Button.
I appreciate your comments if I'm missing something really basic in this scenario.
(Adding more details)
I tried a different thing with the restrictions as you can see in the last two images, now I can see "something", but it's not respecting the positions.
You are using size classes of regular width & regular height (wRegular hRegular).
Design your popover view controller in Any-Any size and it should be OK.
(You can also uninstall the size classes of any object in that view controller)
There are some problems in your constraints.
The Label should have 3 constraints: left (Leading), right-to-the-text-field (Trailing) and top (Top Space):
The width and height are not needed because they are automatically set from the intrinsic content size of the label text ("Label").
IMPORTANT: When you add the constraints be sure that they are absolute, not margin related (to understand the difference read this blog post iOS8 Layout Margins).
The Text Field should have the following constraints: width and distance-from-top (Top Space):
Note that the second ("Leading Space") is the same of the "Trailing Space" of the label, not an additional one (the constraints are 5 in total).
You have to explicitly set the width of the text field (134 in my example) because otherwise the intrinsic content size will be set (and it is near to 0 because the text field is initially empty). The height is set correctly from the intrinsic size (calculated from font height, also if text is empty).
NOTE:
My answer implies some important Autolayout concepts. I advice you to study the Apple documentation to better understand them.
Hope this helps

Resources