Making large toolbars like the iPod app - iphone

I am trying to create a toolbar programatically (rather than via IB) very similar to the toolbar featured in the iPhone app:
Currently I've been experimenting with the UIToolbar class, but I'm not sure how (and if?) you can make the toolbar buttons centrally aligned and large like that in the iPod app.
Additionally, regardless of size, the gradient/reflection artwork never correctly respects the size and is stuck as if the object is the default smaller size.
If this cannot be done with a standard UIToolbar, I guess I need to create my own view. In this case, can the reflection/gradient be created programmatically or will it require some clever alpha tranparency Photoshopped artwork?

The best thing you can do is:
create MyToolbar.h and MyToolbar.m : MyToolbar can be inherited from UIToobar
create an empty xib named MyToolbar.xib
In Interface Builder, add a new UIToolBar with "IB->Tools->Library"
With "IB->Tools->Inspector", change the class identity to "MyToolbar"
Now, you can customize your toolbar with IB or with xCode as you want.

Related

Swift scrolling controller for list of buttons

I'm building a macOS app that requires a scrollable (and ideally, drag and reorderable) list of check box buttons. These buttons are going to be loaded in from a .plist file, so I need some control to load them into.
I'm really a c# programmer, and would just use a stackpanel or dockpanel or something of the like. Is there an equivalent in swift? Or do I need to write a custom control?
I have tried using various types of table views with check box cells, as well as rule views and other scrolling type views.
Edit:
Sorry, I should have linked to NSCollectionView and NSStackView for MacOS — it's obviously not part of UIKit. :)
//
Check out UICollectionView. Similar to UITableView (data source, delegate, UIScrollView subclass), but more flexible on how the layout looks and acts. It also supports reordering.
You could also use a UIStackView, but you would have to put it in a UIScrollView yourself and it doesn't easily support reordering.

How to make a custom Swift popup window on iPhone

I'm wanting to implement a custom popup window within an iPhone app that contains buttons and labels.
One solution I've found is to simply create a hidden UIView in the same View Controller (How to make a popup window with an image SWIFT) and then making hidden = false. I feel like this shouldn't be the "best" way to do this, just due to the way I'll be working with multiple interfaces in the same View Controller.
Another method is forcing a non-fullscreen popover on iPhone (http://richardallen.me/2014/11/28/popovers.html), but this doesn't seem to play well with containing other elements like buttons and labels.
Is it possible to create a custom popup window for iPhone - which can hold buttons and labels - that can be implemented from a separate View Controller in my Storyboard? It has to be in a way that doesn't hide my main UI behind a fullscreen popover. Preferably one that can be easily animated using UIView.animateWithDuration.
Just looking for some starting directions so I can go learn more about implementing it. Or is stacking it with my other UI in the main View Controller the best way to go?
add a UIView container and make it's alpha = 0. If you want to show it you can increase the alpha to 1. And simply add a exit button to your container to decrease the alpha to 0.

Convert iPhone app to universal app: Grouped UITableView

I am using xib-s for my UITableViewCells on iPhone. Now I need to convert my app to universal app. Do I have to create new xib-s (looking exactly the same way) for the iPad version? My current problem is that I am using grouped UITableViews. As the left and right margins on both devices differ, some of the controls on iPad are partly "out of the cells".
In case I need new xib-s (looking exactly the same way), do I need separate properties for the controls in the ViewController? For example, for a label named myLabel, do I need a second property myLabelIpad or is there a better way to handle that?
Cheers
My suggestion is to create new xib. But if there are small changes , then you can maintain one xib. However it depends on how different your iPhone / iPad versions are. For example, if the iPad version is just a bigger version of the iPhone one with a few extra buttons, etc, it's easier to use one UIView and just set the frames of the subviews appropriately.
First understand what you are up to. How do you want your iPad app to look like? How does it navigate. Ceratinly you want to leverage from the lager screen of the ipad. When ever you do that and the auto-resizing mechanism is not sufficient (which it rarely is) then go for a separated xib file.
Second - for each XIB which hosts the same number and types of UIView and UIConrol subclasses, you should be able to use the same view controller for two separate XIBs. Just link all conrols within both XIB to the related IBOutlet properties and IBAction methods alike.
However, when you take leveraging from iPad capabilites seriously then you are like to end up with a different set of view controllers. That is when you can combine the controls of several iPad views wihin one single iPad view and similar cases.
Nevertheless, think of using popups. The content of a popup could nicely correlate to what is a full screen on the iPhone. In that case you can use the same view controller again within that popup container.
Does this sort of answer your question? If not, then please be more specific.
Actually you can retain the same Table cell xib files. You just have to get the Auto resizing masks of the cell and its subviews right.

How to realize the same effect like iPhone's homescreen

I want to add some custom buttons and realize the same effect like the iPhone's home screen. What I can think of is to calculate the position of each button and add them to the view. Are there any other ways to do this? e.g. add buttons to the tableview
Check TTLauncherView from Three20,
I realized the same view of the thumbnails in the photo app (which in principle differs only because of the background color and the rounded effect of the buttons) using a custom cell (with 4 UIButtons inside) in a normal tableview.
In my case, this is because I need to scroll up and down, in your specific case there should be a way to "lock" the table from scrolling. By the way, for this reason, it could be simpler to design the custom view in the interface builder, it is very quick to design such a view, and then create a custom controller to provide simple methods to assign icons and actions to the UIButtons dynamically.
You could also look at the Three20 libraries as already suggested, it is already implemented, but you app will easily be rejected by Apple if you do so.

Custom iPhone control using UIViewController subclass

I wanted a control like the UISlider, but with two thumbs instead of one so you could specify a range instead of just one value. I read up on other people looking for the same thing and suggestions about making new controls were over my head.
So I decided to setup what I wanted in a nib and then created a view controller to handle its behavior. It actually works really well this way accept for 2 things.
1) To load my 'custom control' into another nib I need to do it through code like this...
MaxMinSliderViewController *feeMaxMinSlider =
[[MaxMinSliderViewController alloc] init];
[self.view addSubview:feeMaxMinSlider.view];
feeMaxMinSlider.view.frame = CGRectMake(20, 20, 280, 54);
...instead of dragging and dropping into other nibs like normal IB controls. Is there an easy way to be able to do this?
2) In all my reading about doing this, its seems as though I was supposed to (to do it the right way) subclass UIView instead of UIViewController. I couldn't setup the UIView correctly and get it working though.
Thoughts?
instead of dragging and dropping into
other nibs like normal IB controls. Is
there an easy way to be able to do
this?
Nope! There's only an incredibly hard way!
Assuming you manage to convert your class into a custom UIView instead of a UIViewController you can do part of this quite easily within Interface Builder (depending upon what kind of init method your custom control has).
Within Interface Builder drag and drop a plain old UIView from the Library Window onto your view and position/size it as required.
Then with the UIView selected, switch to the Identity tab of the Inspector Window (the tab with a little (i) icon on it) and change it from UIView to the name of your custom class. This causes an instance of your custom class to be instantiated when the NIB is loaded, instead of an empty UIView.
You can then hook up the view to an IBOutlet etc as normal.
The advantage of this approach is the ability to position and size your control visually etc. It does however only appear as a rectangle, and you don't get the ability to graphically configure the additional properties of your control as you would with a UIButton or similiar control which Interface Builder has additional support for.
I find this technique great, as I'm not that much of a visual thinker and find it hard to picture in my mind how things will look when I read a section of code containing lots of frame = CGRectMake(20, 20, 280, 54) etc. Being able to do it visually with a mouse is much better for me.
There is an Interface Builder Plug-in Programming guide, but it only mentions Mac OS X, not the iPhone.
Also, as of XCode 3.2.1, there is only a new project template for creating a Mac OS X IB Plug-in; there is no such project template for iPhone (Cocoa Touch). So my guess is this is not applicable for the iPhone.