can i make the searchbar static in iphone application - iphone

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];

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];

UITextView is not scrolling

I want to display one paragraph in UITextView. I'm able to put the content of paragraph in Text view, but I'm unable to scroll UITextView (Some of the content is not visible as it's not scrolling).
What I'm trying to do is:
CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:#"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:NO];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:#"Hi,I'm working fine with this space"];
[self.view addSubview:textview];
In this case, scrolling is enabled. Can any one tell me why it's not scrolling?
set [textview setUserInteractionEnabled:TRUE];and I think you dont want to keyboard to pop up then you can hide the keyboard by implementing the uitextview delegate methode -(void)textViewDidBeginEditing:(UITextView *)textView{[textView resignFirstResponder];
set YES for setUserInteractionEnabled property of UITextView
set this line
[textview setUserInteractionEnabled:YES];
instead of
[textview setUserInteractionEnabled:NO];
I have a ViewController that only has a text view with about 5 pages of text.
Here is what I did in Swift 4.0:
Very important: Make sure you have auto layout set on the text
view. In my ViewController, I set my constraints to the text view
to 8,8,8,8 with constrain to margins checked. The whole thing does
not scroll if auto layout is not set.
This is the code I used:
Swift 4.0
textForPrivacyPolicy.showsVerticalScrollIndicator = true
textForPrivacyPolicy.isEditable = false
textForPrivacyPolicy.isScrollEnabled = true
textForPrivacyPolicy.scrollRangeToVisible(NSMakeRange(0, 0))
textForPrivacyPolicy.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
Paste this code
CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:#"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:YES];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:#"Hi,I'm working fine with this space"];
[self.view addSubview:textview];
Add this line : [textview setUserInteractionEnabled:YES]; in place of this:
[textview setUserInteractionEnabled:NO];
Set UserInteractionEnabled as YES.
I had the same issue and I had setscrollable and userinteractionenabled to TRUE. It turned out to be a problem with Constraints. In order to fix this, click on your view controller in ur storyboard (the battery icon on top right), then go to "Editor"->"Resolve Auto Layout Issues"->"Add Missing Constraints In ". Fixed the issue for me!
bapi rout , There is a property for the user interaction with textView. You have set it to No. If you want to perform scroll on TextView, You have to enable this property.
[textview setUserInteractionEnabled:YES];
This will help you.

Side sliding tabs in iPhone/iPad application

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.)

How can I add a UIView above viewable area of a UITableView?

I understand that there is a tableHeaderView property, but when ever I add my view to that, it is not hidden above the scroll area.
What I would like to have is, my custom view shown when you pull down the tableview and hold and you see my UIView brought into view. This is done on many apps to put a logo or such slightly hidden until a user pulls down on the tableview (Twitter/Facebook when you pulldown).
I am currently using the following and it is not putting it out of the view:
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
l.text = #"Hidden Text";
l.textColor = [UIColor redColor];
self.tableView.tableHeaderView = l;
[l release];
Since UITableView is actually a UIScrollView with some extra functionality, you can use contentInset to obtain the effect you want. The trick is to use a negative value for the top inset. This will normally hide your header view, but it will still be viewable when the table bounces.
So, after you add the label to the header view, just set the contentInset like this:
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
l.text = #"Hidden Text";
l.textColor = [UIColor redColor];
self.tableView.tableHeaderView = l;
//add this
[self.tableView setContentInset:UIEdgeInsetsMake(-l.bounds.size.height, 0.0f, 0.0f, 0.0f)];
[l release];
The best solution here is to add your view to the header, as you had mentioned you tried, and then in your controller's viewDidLoad actually scroll the tableview downward programmatically until the header view you wanted hidden is hidden. This can be done a number of different ways. The easiest is probably:
[self.tableView setContentOffset: CGPointMake(0, myHeaderHeight)];
Simply have a 0-height header view, and then have a subview of that be positioned with a negative y, and so that the bottom edge of the subview is the top of the view.
UIWindow* window = [[UIApplication sharedApplication].delegate.window;
[window addSubview: your-overlayview];

Could Not able to position the UITableView?

- (void)loadView
{
SettingsTitleBar=[[UINavigationController alloc] initWithRootViewController: self];
searchBar =[ [UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 40)];
searchBar.placeholder = #"Type your City Name";
searchBar.delegate = self;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
[searchBar setShowsCancelButton:YES];
[SettingsTitleBar.navigationBar addSubview:searchBar];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 85, 320, 392)];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 120, 320, 302) style: UITableViewStyleGrouped];
[tableView setDelegate:self];
[tableView setDataSource:self];
[self.view addSubview:tableView];
}
I Have a UITableViewController,
I have utilized the first 44 pixels height for title bar, and then the next 40 pixels of height for search bar(44+40). These are added as navigation controller subviews. then i am adding my self.view at 85 pixel from top, finally tableview has been added as child to the self.view . But table view has been overlapped with the Searchbar. I dont what is wrong with it. I tried to change various yPositions of tableview and self.view but still nothing happened.
Can anyone able to help me out from this ?
Note : I dont want to add SearchBar into UITableviewHeader Section.
U can make the view of size 320X436 and add the tabble view and search bar in that view...
I wouldn't add subviews to the navigationBar. Add it to the view.
As a sidenote: anything you alloc (or retain or copy), you should release or autorelease
I had trouble with this too, initially. Don't worry about adding the searchBar as a subview. Simply do this:
self.tableView.tableHeaderView = searchBar;
The searchBar will be treated like a header. You'll want to change the CGRect's size to (0,0,320,44), however.