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.
Related
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.
I would like to know how to change the keyboard background color programmatically in iOS? The background is normally grey but I need clear background color (behind letters).
There are no direct properties which would let you do that. One option is to create a custom inputView
Another is to get all the views from the key window, find the view for the keyboard and make changes. But this is not advisable and can break at any point.
I followed this tutorial http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/ to add more button beside delete button when swiping.
But the problem is the cell need to use clear color so the background image can be seen. But that approach used scrollview to display the content view and the buttons view of tableview cell. If the content view of the scrollview has any background color instead of clear color, it can hide the buttons so these buttons only display a part determined by our finger when swiping on the cell, using clear color for background makes these buttons show without the need to swipe from right to left on the cell.
So anyone can give me a suggestion to use the clear color to display the background image without revealing the under buttons?
You can use MGSwipeTableCell class for creating swipeable buttons with any colour you need. It will not interfere with the tableview cell color as well. It is very easy and quick to implement.
https://github.com/MortimerGoro/MGSwipeTableCell
I'd like to create a function that essentially translucently greys out the screen. For example, if you hold the off button on an iPhone/iPad the screen greys out and gives you the option to turn off the device. I'd like to implement the same type of thing. If a function is called, grey out a screen and include a button on the screen, and if the button is pressed it goes back to normal.
My guess is that you would create some sort of new view and place it on top of the current view, but I am not sure how to do that.
Create a UIView subclass that has a background color of [UIColor blackColor] and set the alpha value for that view to 0.5. When you add it as a subview over whatever you view you want to obscure, it should look roughly like the "Power Down" screen tint.
Add a button to that (at full alpha) and it'll look super slick.
I'm trying to use the standard highlighting logic for a UIButton but set the background image for the Normal state. When do this programmatically everything works fine, but when my button is set in Interface Builder I get the following results:
Has anyone run in this where the standard highlighting is changing the way the background image looks? Just to be clear I want the color change, just not the squared off corners on the left.
Figured it out. Apparently if my button size is smaller than the background image it scales appropriately for Normal State, but the highlighted state causes this strangeness. Good to know since I'm attempting to use a single image and just scale it for all of my various buttons.
In this case my IB button was set as 77pt wide, but my image is 97pt wide. It finally looks correct with my IB button set at 90pt wide or larger.