Side sliding tabs in iPhone/iPad application - iphone

Is it possible to create a side sliding tabs (like the menu in WP7; I'm not sure what the correct term is) for iPhone/iPad applications? I haven't implemented any code yet, right now I'm assuming that it could probably be done with multiple vertical UIScrollViews within a horizontal UIScrollView.
I've seen this kind of menu in iPad applications (Discovr Music/Movies), and would like to implement it in iPhone if it is possible. Also, is this kind of menu against any of Apple's UX policies?
Thanks!

This is possible and you can do it.
For example:
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 460)];
UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[wrapper addSubview:subView1];
UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];
[wrapper addSubview:subView2];
[scrollView setContentSize:wrapper.frame.size];
[scrollView setPagingEnabled:YES]; //Here's what you want to do!
[scrollView addSubview:wrapper];
Didn't test the code, but it should work.
Important is to add Subview to the ScrollView. (It would also work if you don't use a wrapper, but I often use it, because of the size.)

Related

Two picker views in the same UIViewController

I have a UIViewController that contains two picker views. For some reason when I run the project one picker view is overshadowing the other. How can I set the positions, height and other parameters in code?
Why are you using two picker view ? You can change the content of the pickerview when needed.
Even if u want to use two of them, the picker would be at the bottom anyways. Use show and hide property of the pickerview to handle your required task
You have to implement -initWithFrame: method (assuming that you're instantiating the view in code). Here's an example showing to picker views -
UIPickerView *myPickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
[self.view addSubview:myPickerView1];
UIPickerView *myPickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 320)];
[self.view addSubview:myPickerView2];
If you see this image below, they are not overshadowing one another. I hope this easy explanation helps. Welcome to iOS Development!
you can do this way
//first picker
optionPicker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 200)];
[self.view addSubview:optionPicker1];
//second picker
optionPicker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
[self.view addSubview:optionPicker2];

How to add a view on button click without using interface builder

I just did it like this
-(IBAction)clickButtonPressed:(id)sender
{
NSLog(#"Clicked.........");
UIView *showView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:showView];
}
This action called & There were no any error coming but this view is also not shown.
Try setting the view's background color to make sure that it is not actually added without you noticing, also release your view after adding it (if you are not using ARC)
-(IBAction)clickButtonPressed:(id)sender {
NSLog(#"Clicked.........");
UIView *showView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
showView.backgroundColor = [UIColor blackColor];
[self.view addSubview:showView];
[showView release]; // if not ARC
}

How to enable UISearchBar grey out view?

I am using a UISearchBar and once the user taps the bar (and the keyboard pops up) I want the everything besides the keyboard and UISearchBar to be greyed out. Similar to safari when the search is selected. I do not need past searches. See here:
Anyone have any ideas? I've looked through the questions here on StackOverflow and I can't find anything specific.
Thanks!
You can create a UIView that contains the UISearchBar. And then you can set UIView's backgroundColor to get the gray background.
And here's some sample code:
UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 20, 320, 460);
view1.backgroundColor = [UIColor grayColor];
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.frame = CGRectMake(0, 0, 320, 50);
[view1 addSubview:searchBar];
[searchBar release];
[self.window addSubview:view1];
[view1 release];

iPad - How to move Mulitple UIViews side-by-side

How to move multiple UIViews Side-by-Side just like an twitter application working in iPad. With full of effects animation and rotations.
You should take a look at the UIScrollView with paging enabled.
Make all your views and put them next to one another inside a UIScrollView. i.e.
// Get your views
MyView *v1 = [[[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
MyView *v2 = [[[MyView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)] autorelease];
MyView *v3 = [[[MyView alloc] initWithFrame:CGRectMake(640, 0, 320, 480)] autorelease];
// Make the UIScrollView
UIScrollView *scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[scroll setPagingEnabled:YES];
[[scroll addSubview:v1];
[[scroll addSubview:v2];
[[scroll addSubview:v3];
[scroll setContentSize:CGSizeMake(960, 480)];
// add the scroll view to your view
[[self view] addSubview:scroll];
Now, the three views (v1, v2 and v3) are next to each other in a scroll view whose content is much wider the view. With paging enabled, they will scroll left and right but won't stop halfway through a view.
Take a look at view animations:
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone

can i make the searchbar static in iphone application

I want that searchbar should also scroll with scrolling mean when i scroll down searchbar should be visible.
as there anyway to do so...
thanks. and sorry for my bad english..
If I understand you correctly, this is what you should do:
Open up the interface builder and make the SearchBar the child of the table view if you want it to scroll along with the contents. If you need it to be always visible, drag it out of the tableview.
Well you can also simply do that
SearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(10, 5, 300, 50)];
SearchBar.tintColor=[UIColor blackColor];
[SearchBar setDelegate:self];
//[self.view addSubview:search];
table=[[UITableView alloc]initWithFrame:CGRectMake(0, 15, 320, 480) style:UITableViewStyleGrouped];
table.delegate=self;
table.dataSource=self;
table.backgroundColor=[UIColor darkGrayColor];
table.tableHeaderView=SearchBar;
[self.view addSubview:table];