ios greying the screen - ios

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.

Related

Keyboard flashes from opaque to transparent upon push

I have a view embedded in a navigation and tab bar controller. When a button is pressed, it pushes to (shows) the next view and I programmed the keyboard to immediately show for the first text field [textField becomeFirstResponder].
However, the keyboard will be opaque instantly then turn transparent in a little less than half a second. This happens no matter the keyboard type or keyboard look. I have no idea what is causing this, and I cannot find any answers anywhere else.
Other details: the navigation bar is translucent, and the bottom bar is hidden on the view we push to. The background is an image. This problem does not occur if I remove [textField becomeFirstResponder] and have the user just select the text field, but that is not what I am trying to do.
I have a similar scenario and also ran into this issue.
I am push-segueing between view controllers, and the keyboard has to stay up during the segue (textField.becomeFirstResponder() is called in viewWillAppear(_:)). The view controllers' background is white, but the keyboard look is Dark. During the segue, the keyboard is black, and then turns gray as soon as the segue finishes.
I came up with a workaround for that - it works if you want to have the keyboard opaque-ish at all times.
Add an empty UIView to the view controllers where you want to show the keyboard instantly, and set the backgroundColor of the view to match your keyboard's look (black for Dark, white for Light). Pin that view to left, right and bottom edges of the view controller's safe area superview. Add a height constraint to it equal to 0 and make an IBOutlet for it.
In your view controller, subscribe to KeyboardWillShow and KeyboardWillHide notifications and control the height constraint of the view you created - make it match the keyboard's frame height (the keyboard's frame end).
You will still see that during the segue, the keyboard stays opaque, but when the segue finishes and keyboard transparency kicks in, the effect is much less visible.
Ideal scenario for me would be to be able to turn off the transparency of the keyboard completely, but I don't think it's possible. I also think there is no way to make the keyboard non-opaque during the segue, so the only option is to make it look opaque at all times.

iOS UIToolbar recognizes touch

I made a vertical (in looks) toolbar programmatically. Using initWithFrame I set the width and height of the toolbar and sent it to extreme right.
Now I added a bar button item to the toolbar and set an action for it. But when I click anywhere on the toolbar, the action message is being sent. And I checked the sender, the sender is not the toolbar but the button.
I tried on another toolbar which I placed horizontally, the buttons are seen as tapped if I click in the vicinity of the button. And since now my toolber is vertical (but horizontal according to iOS), clicking anywhere on the toolbar calls the function.
I want to send the message only when I click on the button and not on the toolbar.
I want to use the camera icon provided by apple, so I am not in favor of using UIButton. (I can set a custom image, but it would be good if i can avoid that)
I also think that placing a horizontal toolbar and using CGAffineTransform can solve the problem. But it would be nice if there is clean method.
Using the transform is definitely the way to go.
Run the identity transform through this function and set it as the transform on your bar. I think it is a very simple solution.
It shouldn't be hard to set the transform right after you init with a normal frame. To avoid stretching you can make that frame using the values you are already using but swapping the x and y.
I don't believe that UIToolbar supports vertical orientation; you'll probably be better off rolling your own toolbar-like control.

Simple Horizontal Button Bar for iOS

I have a requirement for a very simple Button Bar.
It should take up the width of the screen.
It should allow at least 3
buttons.
The buttons should be of equal width and together take up
the whole width of the bar.
Each button should be tappable, but not
have a selected state.
The bar will be overlaid on a MapView and positioned directly above a TabBar.
Tapping a button will launch a Modal ViewController.
I thought about using a UITabBar and not allowing its tabs to become selected, but the HIG is pretty clear that this is not correct usage and UIToolBar doesn't allow the button widths to be set.
This seems like a very simple requirement but I can't see an obvious solution. Is there something I'm missing? Can anyone suggest a solution?
What's wrong with just creating a simple view that draws an appropriate gradient, and then adding three buttons of the appropriate size?
If you're feeling ambitious, or if this is something that you're likely to use more than once, you could even have the view create the three buttons. Call it ThreeButtonBar or something. Give it a constant height and adjust the width to match that of its superview so that you can use it in portrait or landscape orientation.

iOS : How to create a close button that sits on the edge of a UIView with rounded corners (using IB)?

Background:
I am working on an iPad app that will pop a custom view when the user clicks on an image.
I want the view to have rounded corners and a close button ( red x in a circle ) that sits on right top edge.
The button in half inside and half outside the view.... Take a look at the Kayak or Zynga Poker apps to see what I am talking about.
Question : If I create the view programmatically and add the button, it works.
However, I really want to user a nib to create the view so I can design the view correctly. So when I call self.layer.maskToBounds = YES on the view ( to create the rounded corners with a radius of 25 ), it clips my button ( since its half in and half out ). How do I retain my button without it getting clipped and still have rounded corners ?
Sounds to me like you are using a view and a button. What you might try is using a third container view (with clear background) in which you place your original view and your button. The button will need to be on top of the view, so to speak, so it is not obscured by your view. But that should allow you to have properly rounded corners on your view (not the container view) and have your button fully visible.
Some settings, such as maskToBounds, cornerRadius, aren't available in IB. You can create the entire view using a NIB except it won't have rounded corners in IB and in viewDidLoad you set just those properties that couldn't be set in IB.

How to have a "Back button style" in the UINavigatorBar / Button

I have a UINavigatorBar and dropped a button to the left top corner in the Interface Builder.
Simple question:
The Button is round, how I can set the button to a "back-style" button?
(I mean, that the left side of the button is not round, it should be a arrow).
I just put together a simple UIViewController subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear/willDisappear logic to animate the back button the way the UINavigationController does while using the leftBarButtonItem property. You'd just have to swap out the back-button PNG and change your colors in a subclass.
https://github.com/typeoneerror/BBCustomBackButtonViewController
If you want the back button to go back to the last view in the hierarchy, just leave the button off of the top left corner, and it should show up automatically.
Otherwise, you may need to subclass UIBarButtonItem.
I think if you want to do this with a UINavigationBar that does not work in conjunction with a UINavigationController you need to create a custom view for the button that is shaped like the back button.

Resources