I would like to create a control for Apple Watch (using WatchKit) that resembles the iPhone UISegmentedControl.
Has anyone managed to achieve this on Apple Watch already?
I followed the suggestion of a user and used buttons and custom background colours to achieve this. However the issue I got now is that they do not align horizontally. Any way to do so?
Place your buttons in group with horizontal layout, make their widths relative to container with 0.5 value. Also you can set zero cornerRadius for buttons.
Just add your controls into WKInterfaceGroup,set its layout to Horizontal and tweak controls width in Interface Builder.Set spacing explicitly to 0 to override default value(2 pts).Here is the screenshot that illustrates the result.
You can group your buttons as Vladimir described if you really want to create a segmented control. However, if you do, you should probably use a shorter label than "Standby" for the third option, so that your tap targets can all have a consistent size.
Also, you might consider reworking your UI in such a way that you can eliminate the third option, be more explicit about what you're controlling, and use built-in controls with larger targets. For example, would something like this be possible?
Related
I've been using size classes to hide and show certain views by adjusting / animating their constraints to move them in and out of view.
This is sufficient for a lot of cases but I want to see if a different approach is possible.
I want to know if it's possible to completely remove a component from the screen based on size class.
For example,
While in landscape mode I have 4 buttons on the screen.
When switching to portrait mode I remove 2 of the buttons.
Ideally I would like to achieve this using just storyboards.
Thanks,
You can "remove" a control on specific size classes using the installed checkbox in the Attribute inspector :
I've been doing iOS for a while now, but when it comes to dynamically hiding / showing elements, I'm a bit lost.
Coming from Android, I'm used to being able to simply set views to visibility gone, but this doesn't exist on iOS.
So let's say I have the following scenario:
Basically I want to have a table, but the table should not fill the entire view controller. Instead it should leave place for optionally either a button, a multiline label, or possibly both at the bottom (if visible, these should be fixed, not scroll).
One way to solve this would be to use auto layout and modify constraints, like adding a zero height constraint. But that would make iOS kill one of the other constraints, which would make it hard to change it again. For the label, I wouldn't always want to have a height constraint, because it could be multiline, and should take the size it needs.
Maybe it's easier to skip autolayout here and modify frames instead, I don't know.
My question is: What approach would be best here?
Is there some other way of doing this I haven't thought of, or do I have to try to do what I described above?
I'm not primarily looking for code (code can be ok), but I'm more interested in a description of how it can be done.
I'd like to support iOS 7.
This problem had a variety of solutions, and opinion based, but I'm facing such questions a lot, when I don't know what to choose and what would be the "right thing".
So, I my opinion, the best solution here is using autolayout, you need to set height of label manually, but you have a few methods for this, at least you can play with it and if you don't succeed ask question about it. Using frames, you'll face same problem of calculating height, right? But with auto layout, you only need to set height, vertical space to 0, when you need to hide message.
You can also use constrains with priority lower 1000, and remove completely constraints from message (button, label) if you don't need it at all anymore.
For example, taking your layout image, you can make UIView with subviews: button, label. Top constraint connect to the UITableView, other constraints to the sides.Label and button will calculate the view's height. The only question here is label height.
So in ios assuming that the background of both these objects is opaque only the front most view in the Heirarchy will be visible and interactable, An easy solution would be to change the different frames of these two things you need and make sure they are in the back of your view heirachy, and when you need them to appear use view.bringSubviewToFront(mySubview) and view.pushSubviewToBack(mySubview) to make it disappear again. View obviously would be referring to main view of your view controller.
I have already developed an IOS app in Objective C, Xcode 6 in which I have disabled the auto layouts and size classes.
Is it now possible to use auto layout after having disabled it earlier?
If yes, how can I implement it? When I enable the auto layouts and size classes and I implement the constraint on the label, the background colour of the label changes to white. When I do this for other object types, they become invisible.
To answer your first question, yes: it is indeed possible to use Auto Layout in an app after having disabled it. Each Xcode project template just gives you an initial starting point – nothing is set in stone.
For the second question, the best way of implementing Auto Layout in an app is to just take it one view at a time. You don't need to go all-or-nothing with Auto Layout; it's possible to just use it in certain cases but use frame based layout in others. Start on smaller, easier views and go from there.
The last issue around background colors is a little trickier without having screenshots or code samples. I have had views disappear on me after implementing Auto Layout and the issue always boiled down to bad constraints. The best solution I can give there is to just do the usual view-debugging work (as in, printing frames and manually setting bright colors to see where views actually are) and figure out what is going wrong.
Having the background color change to white is interesting, though... Auto Layout should not be affecting that at all. It sounds like the background color got changed somehow while the constraints were being created.
In our application we are showing the segmented control with dynamic segments.
If number of segments is 2-3 we have no issue, but if number of segments is 5 or more than that then the text in segment is not readable.
See the above image.
So, what is the alternate way to resolve this issue?
There are a couple of solutions.
You could use a UIPickerView instead of a UISegmentedControl
You could show three segments, where the first two segments are the most often used segments, and touching the third segment shows a UIPickerView with all the options.
You could embed the UISegmentedControl in a UIScrollView. Make sure to size your segmented control in a way that shows that it is indeed scrollable.
Which one fits best depends on your app, and what is the actual use of those segments.
It's hard to answer this question on a general basis. Apple's Human Interface Guidlines may be a good reference for this kind of issues.
The best Solution is that add ScrollView in you view controller and add UISegmentController to UIScrollView and give fix size of your segment button and change size of UISegmentController Base on total numbers of button and also change content size of UIScrollView base on UISegmentController.
try setting font size for the test to be smaller, that ways, the text will be more visible.
However, if your number of segments keep increasing, that wouldn't be a solution
Is there a ways to adjust the width of the padding between Cocoa Touch UITabBar buttons? I'm working on an iPad project and I would like to reduce the padding between buttons for a slightly tighter look. Am I out of luck?
You could take a close look at TabBarKit and see if it suits your requirements. It doesn't explicitly mention that you can adjust spacing etc, but at least the code isn't a black box which would enable you to see if adding such functionality is within the realm of possibility.