iPhone UIToolbar with UIActionSheet style buttons - iphone

I have an main window containing a UIToolBarController. In my first tab, I load a UIViewController, where I have an MKMapView. Above the map, I would like a toolbar like on the screenshot below (basically, instead of their UITableView I have an MKMapView...):
I'd like to know how I can make this big toolbar on top, and would like to add just une UIActionSheet style button ("Start" in green, and when clicked switch to red "Stop").
Thanks!
PS: The app from the screenshot is Clock if you want to try.

I don't think it is a toolbar or an action sheet. Your picture shows a UIView with two UILabel objects and two UIButton objects. The UIButton objects have pretty png files as their background images.
The UITableView is simply made not to take the whole screen. In IB a UITableView will normally try to take the whole screen, but you can always resize it.
So, if I was going to try to make this interface in IB I would start with a UIViewController and I would add a UIView (if it wasn't already there). I would resize the UIView to take up half of the screen. Then I would add a UITableView and resize it to take up the other half of the screen. Then I would add the two UILabels and the two UIButtons.
I would wire all of those things to my UIViewController's file. The UIViewController file would have 1 #property that was a UIView, 1 #property that was a UITableView, 2 #properties that were UILabels and 2 #properties that were UIButtons.

Related

Drawing text to a custom UIView in a UIScrollView

I have a UITableView and a UITableCell subclass. I'd like each table cell to have a UIScrollView with a custom UIView. The custom UIView will include a series of NSStrings from an array. I'd like the UIScrollView to horizontally page-scroll through the NSStrings in the UIView.
I can't figure out how to implement the custom UIView and draw the text to the view.
It was a suggestion from someone on my previous post, that I should draw the strings onto a custom UIView, rather than use UILabels. UITableView scrolling slow, memory leak issue
I have referred to both Apple's TableViewSuite and AdvancedTableCell projects, but I cannot grasp how to implement for my case.
Just use UITextView instead of UIView and UILabel if you don`t need editing you can turn it off using .editing property.

Fix UIButton on top of UIScrollView

I'm trying to figure out how to overlay a UIButton on top of a UIScrollView. Basically the user would be able to use the scrollview normally. But a button in the top right of the scrollview would remain in a fixed position. Any thoughts?
Don't add the UIButton as a subView of the UIScrollView, but instead of "self.view"
In the InterfaceBuilder there will be a Hierarchal list of items you put in your view, drag the button from being a view belonging to the scrollView to belonging to the view containing the subview.
Your view hierarchy will look like the following
mainView
|
----Button
|
----ScrollView
Instead of
mainView
|
----ScrollView
|
----Button
basically It means both your button and your ScrollView will both be subViews of the exact same mainView. If your scrollView is the mainView put an empty UIView above the scrollView and insert the UIButton & UIScrollView into that
IB is a little finicky when dropping new views directly on the 'fake' interface. What you will need to do is go over to the left in the list of views and select your button view. Now drag it up to below the 'self.view' or whatever is your top level view.
YOu should notice as you raise it up and down in the list that a light blue line will appear. The width corresponds to 'subview' or 'parent' view connection. Play with it a bit to see the difference.
When you feel comfortable, you should be able to place the Button in the 'self.view', not as a subview of the scroll view. Additionally, if you want it to appear on TOP (physical 'Z level') you will need it to be below the scroll view in the list. ( this points out a subtle problem with CStreet's solution)

Adding a UIToolBar above a UITabBar - Logic Issue

I need to know the logic of how to write this code.
This is my problem.
When a user taps a button, I need to show a UIToolBar (with a few buttons on it) on the view. This toolBar should appear ONLY above the UITabBarcontroller.
The view is a UIScrollView, so if I hardcode the position of the UIToolBar, it will be displayed in the wrong position each time the user scrolls (Hope you understand what I am saying).
I did the following. I hard coded the position of the UIToolBar (so it will place above the tab bar), and added it to the Window. This sounds like a good solution as the windows size will not change at all instance.
But, I don't want to add this to a Window. So is there any other way I could solve this problem?
I would add an additional UIView to the window so that it acts as a container for both the UIScrollView and UIToolbar. Then resize the scrollview so that it falls short of the toolbar.
You should be thinking of this as layers of views

how to make a custom viewController with transparent black background?

I'm trying to make a viewController appears like the small one in the middle of the picture :
I tried with the UiAlertView, but it semms not offering this feature.
I found some apps adding buttons and labels, photo in similar viewControllers.
Any idea ?
It's not a view controller - it looks like a view that is added as a subview.
The middle View in the image is not a viewcontroller. It is just a custom UIView made up using images and buttons. You can set the transparency of a UIView using property alpha.
Example
yourview.alpha = 0.5;

How to set up UIScrollView in Interface Builder with UI elements outside the main iPhone view?

I am building a data entry form in my iPhone app, and there are more data fields than will fit on the screen. I figured I should put them into a UIScrollView so that the user can scroll through the form. What's the best way to build this in Interface Builder? I know that I can do it programmatically, but I'd like to do it in Interface Builder if I can. The problem is, how can I lay out UILabels, UITextFields, etc. if they fall outside of the main iPhone screen--in the part of the screen for which the UIScrollView becomes useful?
The best workaround I found for this problem (which I consider embarrassing for Interface Builder) is this:
place a "container" UIView inside the UIScrollView, set the size of the container UIView to what is needed (e.g. 320 x 1200) with the inspector and add your content inside that container view. (your buttons, textfields, etc).
set the contentSize for the UIScrollView, in code, to be the same as the size of your container UIView. somewhere in viewDidLoad for example (e.g. scrollView.contentSize = containerView.frame.size;)
To modify content beyond the scrollview's bounds in Interface Builder, you have to drag your container view outside of the scroll view each time, make your modifications, then drag your container view back inside the UIScrollView and build.
This is actually straightforward:
Create a new view controller class e.g. MyScrollViewController
Create a new xib with a UIScrollView as the topmost view, and set the class of the File's Owner to MyScrollView Controller
Set the view attribute of File's Owner to the scroll view
Drag the bottom of the scrollview to create the desired size.
Position your various other UI elements as sub-views of the scroll view
Create and connect an IBOutlet in MyScrollViewController.h for the scroll view, e.g.
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
In MyScrollViewController's viewDidLoad method, add the following line of code:
self.scrollView.contentSize = self.scrollView.frame.size;
Th-th-th-that's all folks!
Set up "Content Insets" of "Scroll View Size" on the "Size inspector": Bottom = YourFrameHeight - ScreenHeight. It will allow you to scroll in ranges of top-to-top, bottom-to-bottom of your UIScrollView
Double click to open the UIScrollView itself in IB, and increase the size to the size you need or bigger (you can always shrink at runtime). Then just add the elements.
EDIT:
Doesn't work - see here instead.
I've had the same issue as well. What I ended up doing was putting another UIView inside of it and setting the height to whatever I wanted. Then I put all my UI elements inside of it. This allows you to drag the inner view up and down.
What worked for me in xCode5 (no storyboard, using autolayout) is using the 7 step answer above the ends with 'Th-th-th-that's all folks!' and adding two steps.
8) Drag a new UIView to interface builder. Not into the Scroll view. Just on its own. Put all your controls/view into that and make it as big as you want. I hooked up this view as contentView.
#property (weak, nonatomic) IBOutlet UIView *contentView;
9) Then in - (void)viewDidLoad
[self.mainScrollView addSubview:self.contentView];
[self.mainScrollView setContentSize:CGSizeMake(self.contentView.frame.size.width,self.contentView.frame.size.height)];
Just saying that made it work for me.
There is finally a sensible solution to all of this and that is to place a Container View inside of the UIScrollView. As Interface Builder displays the UIViewController inside the Container View separately, you can finally see what your UIScrollView content is going to look like without crossing your fingers and standing on your head.
You still need to programmatically set your content size but a least you can now visualise what it going on.