Detect click on WKInterfaceLabel or WKInterfaceGroup in WatchKit - ios

I'm displaying circular progress bar with a label like this:
and I achieve this by creating WKInterfaceGroup and set its image to the animated images, then I put centred WKInterfaceLabel.
Now I want to present another view controller when user clicks on the label or on the circular progress bar. How to do this?

A WKInterfaceButton can have one of two content types: a label or a group. This means you can put your existing group inside a button and have the button trigger the desired action. You can change the button's content type in your storyboard.
I'd suggest taking a look at the docs for WKInterfaceButton.

Related

Label over a button

I'm trying to put a label over a button, but I'm not succeeding...
Here's what I have. I'd like the text "tap to dial" to actually be over the dark grey area, not below it. How do I do that?
On the left side of the image is the view hierarchy, the red things left and right are the button add and button remove, so you get the whole picture.
EDIT: Explanation - The label I'm trying to place over the button is the hint what the button does. The button itself will hold different text contents, thus I need an additional label.
EDIT 2: I don't know why is this question marked with negative votes, why don't people explain that in the comments? Let's pose the question differently: if one wanted to put a label over an image, how would that be done?
Select both objects in IB (Interface Builder) and then create constraints so they have both have the same vertical and horizontal center. If the text is under the button then select the text view and choose "move to front" from the editor menu.
All that being said, why don't you use a titled button with a gray background rather than trying to put a label on top of your button?
A button is a label (that is, its title is). So you don't need a button and a label; just configure the label of the button. The label is the button's titleLabel and you can make it do anything a label can do — including consisting of multiple lines, one of which is smaller than the other, as shown here:
The solution I was looking for was to embed the button and the label in a view. Inside the view they can be positioned to overlap each other, while the view itself can be constrained by auto-layout.

can I create a button with text and image together in Storyboard?

I put a UIButton in my storyboard. It looks simple:
its properties are also simple:
I wanted to include an image in this button, so that it looks as follows:
[image]text
but when I put the image name in storyboard:
the text disappears and all I see is:
how can I show both things together next to each other?
It's just a white title on white background.
You should see the title if you set Text Color back to blue or whatever you wish. For some reason it is different on the screenshots you provided.

Create tab buttons in iOS

This image is just for reference and I want to create tab buttons like in image in my navigation bar. Any idea how to create?
It is segmentedControl. you can just drag and drop from object library from storyboard or you can use it programmatically by making instance of UISegmentedControl. hope this will help :)
Create segmented control:
UISegmentedControl: Displays an element that comprises multiple segments, each of which functions as a discrete button. Each segment can display either text or an image, but not both. UISegmentedControl ensures that the width of each segment is proportional, based on the total number of segments, unless you set a specific width.
More info: Segmented controls
Simply you can use UIsegmented Control. You can just drag and drop it on navigation title . It will work like tab buttons. I hope it will work for u.

tab view like button slides up

I am trying to have a button that is located on the bottom and when the user taps on it it will slide up to show the menu. How is this possible using code or is there an api or anything that I can use to make this possible in the easiest way?
Your screenshot shows a view whose frame is animated when the button is pressed so that either the height of the view, or more likely just the position, is changed so that the view becomes visible. This is a simple UIView animation and the view being added so it is hidden behind the button initially.
Check out the iOS documentation for Animating Views https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
You should be able to create the view and its content either with the interface builder or in code. Start with the view off the bottom of the screen and then use animateWithDuration:animations: using the frame property.

UIAlertView Button outside of UIAlertView

I want to use the UIAlertView Button style outside of the UIAlertView in my View Controller. Again, to be clear, I don't want the button inside the UIAlertView, I just want the button style in my own View Controller.
Does the iOS SDK provide this functionality out of the box, or would I have to make my own custom button to replicate the one of UIAlertView?
The two things you're looking for can be easily achieved in Interface Builder, without even needing to subclass UIButton. They're simply settings within the UIButton class.
Button Size/Padding
To change the padding around the text of a button, the easiest way is simply to change the size of the button. You can do this programmatically, by altering the button's frame, or in Interface Builder by simply dragging the edges of the button to the appropriate size.
Alternatively, you can alter the font size of the button's label, again either programmatically or in IB, to give more room within a button of a given size. Also check out the "Line Break" property, which determines how the button handles text that is too long to display.
Selected Color
A UIButton has several "states," such as Normal, Selected, Highlighted, and Disabled. In each of these states, you can set the button's title, font, text color, background image, etc. What you're looking to do is set the button's background color to white for the Normal state, and gray for the Highlighted state, which unfortunately isn't possible, but there are plenty of SO answers about how to achieve the same effect.
Alternatively, you can set background images by a button's state, so you can set a pure-white background image for the Normal state and a gray background image for the Highlighted state.

Resources