I added UIDatePicker to the UI and gave proper leading and trailing margins. Somehow, a part of W in Wednesday and part of M in Monday are getting cut.
Attached images. I tried increasing and decreasing leading distance from superview but no luck. Can anyone please point me in the right direction?
If we talk about Date Picker, whenever the date with Mon/Wed is selected it is does not get proper space to show the complete info of that particular date. I just try the something with DatePicker.
If datePicker have complete width, then it does not cut 'M' or 'W'.
If i diminished the width after certain level it starts cutting little portion of 'M' or 'W' and inter space between components is manageable automatically by x-code, Now I rotate the simulator, datePicker is working properly because my constraints is according to width of the simulator as it rotated in landscape datepicker get wider.
Suggestion for your problem : Give DatePicker appropriate width otherwise it behaves like this always.
Unfortunately UIDatePicker does not handle change of the width properly and it always cut Wed and Mon words if the width is less than 320. If you really need to make the width lower than 320 you can solve this with CGAffineTransform. You need to keep the width set to 320 and use transform property to change the scale of the view:
self.transform = CGAffineTransformMakeScale(280.0 / 320.0, 280.0 / 320.0);
This will make the UIDatePicker smaller and it won't cut anything.
Related
I want to be able to create a UILabel that will adjust it's size in a more complex way than normal AutoLayout. I've looked over the internet for an answer to this, but to no avail.
Here's what I want it to do.
Say you're viewing it on an iPhone. I want it to be 16 points away from either edge centered in the middle. (Height does not matter in any of this)
However, when the screen gets wider, I want the UILabel to stretch so that it's 16 points away form each edge UNTIL it reaches, say, 500 width. Once it reaches 500 width, I don't want it to get any wider. This is where the 16 points on either side increases, still keeping the label in the center.
Now you're viewing it on an iPad landscape. The UILabel is exactly 500 points wide and in the center.
If possible, I would like to be able to accomplish this using AutoLayout, and not code, but if code is a must, I can deal with that.
Thank you for your consideration. All help is appreciated.
You can do this with 3 constraints:
center the label horizontally in the view
set a width constraint of <= 500
set a leading space constraint of 16. Give this a priority of < 1000.
When the view is wide (like on an iPad), the label will stretch to its full width of 500. Auto Layout will keep the label centered, and it will try its best to satisfy the 3rd constraint by keeping the the leading space as close to 16 as possible. It chooses to break this constraint because the priority is less than 1000.
When the view is narrow (like on an iPhone), the label will have a leading space of 16 (and trailing space of 16 because the label is centered). The width will be whatever is left, because that satisfies the width <= 500 constraint.
I have multiple labels in the storyboard using the any X any Resolution as follows:
Now I have added constraints to the best of my knowledge to force the labels to reposition when an iphone simulator is used and the following happens.
What I would like to happen is have the labels remain the same distance apart from each other proportionally and just resize their font size. So If we were to divide the Iphone screen into thirds Days would occupy the first 3rd, months the 2nd, and Years the 3rd. I thought maybe using aspect ratio for constraints would work but I got the same effect of the labels bunching on top of each other. It looks like they maintain the constraint of distance from the edges but they wont resize themselves to keep the ratio.
Thanks
If you want to keep same distance between each of them, one way of achieving it is:
Give all of them equal widths constraint. and set leading and trailing constraint to zero. Align all labels to centre horizontally.
This way, you wont need to change the font size..
But, however, if you still want to change font, go to attributed inspector for label and under auto shrink: change fixed font size to minimum font size and set it to appropriate value, say 14.
I couldn't really find anything on the web yet, what the Adjustment preference on WatchKit's UI elements does.
Does somebody know?
The adjustment will add or subtract that many points from the size of the element. Say you have an element who's height is set relative to the container at 50% and then you add an adjustment of 10. If the containers height is 100 then that element's height will be 60 since it will be 50% of 100 plus 10. I am using it in my app to get the exact height that I want relative to the height of the watch.
I have a view with labels stacked vertically. The design specification for the view give a vertical offset from the baseline of the text in the top label to the text in the bottom label.
However when I code for this, the size of the top UILabel will always be big enough to accomodate the descender of the top label. So I can only program the offset from the descender, not from the baseline. In the attached picture, red offset is what I want to code for, but I can only code for the green offset. Is there any way that I can get the baseline offset correct either in the xib or through code? I do not want to do this by trial and error, as that would result in the programmed offset not matching the specs.
You can do it, but easier to show you in a screen shot than to explain it:
Change "30" to whatever your specified distance is.
Check out the loading date label. It could be '2 May' or '24 December'.
I want to display the label 'days remaining' after it. Since the width of 'loading date' is dynamic, via auto layout I haven't been able to place 'days remaining' after it. It stays at a fixed distance.
How to adjust it in xcode, using autolayout?
I've been able to achieve it via code by disabling autolayout. However with iOS 7 coming up and autolayout would be essential to maintain iOS 6 and 7 at the same time, I thought it would be a good time to do it with autolayout.
Make sure that the spacing between your two labels is set to auto and that your days remaining label is left aligned. I suggest keeping a constraint between the trailing edge of your days remaining and the superview, but lowering the priority a bit. The goal there is to ignore it when the label should be far away from the superview, but not clip or go outside of the visible area when the date is very long.
You may also need to increase the content hugging priority of the date label and/or decrease the compression resistance of your days remaining label.
You may get better insight into what your labels are doing by setting the background color on them temporarily. The goal is to see how large your labels are, where the text is in the label, and where the spaces are. If there are large gaps between the labels that will help you figure out where to add constraints or adjust the priorities. If the labels are taking up the full width then it will help you get the alignment set correct.