Changing the size of UISearchBar - iphone

Not being able to find the answer, and also not being able to do what I want with this:
CGSize searchBarSize = self.searchDisplayController.searchBar.frame.size;
searchBarSize.width = <someNumber>;
I ask: is there a way to change the width of a UISearchBar?
Thanks a lot.

Just as a reference to anybody with the same problem:
I created a view with the searchBar image (resized) as a button's background (the button was added as a subview to my view).
Then I defined the view containing the button as the view for the table's header in my UiTableViewController.
The button, when pressed, behaves like the searchBar.
I was able to solve my problem.

Related

Swift 3 How to set different background color when selected cell in collectionView

I have two Button and one collectionView in viewcontroller. When I selected Button one and selected one of cell, it looks like this:
and when I selected Button two it looks like this:
So my problem is when I selected back Button one and the collectionView, it should be like the first image.
What should I do so I can get that? Any ideas? thanks
I think you should custom your CollectionViewCell and add mark attribute in that Cell.
When you tap button one that cell. Set value of attribute mark = true.
When you tap button one again you just need to test mark attribute to set cell's background color
to refresh CollectionView (update layout). use
collectionView.collectionViewLayout.invalidateLayout()
Without really seeing any code, I would assume you need to set the background color of cell in viewDidAppear and not viewDidLoad. The reason why is because viewDidLoad only gets called once and if you are hitting the Back Button from the navigation controller and its not setting the color as intended that would be the first step to see if it works like you need.

How to make a contact field entry like this on iOS?

I have an application in which when tapping a button it will show a view to the user to enter the contact number of the user, like in the image below. Can anybody help me achieve this? I need my users to chose their country within the flags and corresponding stdcodes needs to be there
What I see in the example: a UIImageView for the country flag, a UILabel for the country code and a UITextField with a placeholder for the phone number. You can set de value for placeholder in IB or programmatically.
You will have to create a custom view for that.
Steps to do it:
Derive a class from UIView.
Add UIImageView, UILabel and UITextField into it.
Layout it properly.
On button click, show this view with proper frames/bounds.
Create a view like whatever you have shown and initially make it hidden, when user click on the button make the view visible.
ON action event add this sub view into your view
In Xib file,click the label and see the right side properties,In that properties you will find the placeholder option.In that placeholder,type the text you want.That text will be appeared as a hint for the user when he taps it.Or otherwise,directly in your code where you declare the label,in that label code
label.placeholder=#"Enter Contact here";

Adding a button in the bottom of a TableView

I'm trying to add a button on the bottom of a TableView, without any success.
The idea isn't to use the tableFooterView property, as that doesn't show the button in a fixed position.
My idea is more along the lines of the Facebook application's Notifications bar on the bottom.
I'm using Three20.
Any pointers on how I can achieve this?
Thanks
Just add button to the view below your tableview but ensure your table height is less than the position you are adding the button,this way your can scroll table above button & your button will always be visible
Just embed custom view over your tableview.i mean on the bottom of tableview.so the tableview will scroll and the view don't.
Add a UIView as the footerView and then add the UIButton to the UIView.

UITableViewController with a UIPickerView sliding up the screen

I have a UITableView where a cell needs to be filled in with a date by selecting it through a pickerview. Instead of pushing the pickerview onto the navigationController I would want to let it slide up halfway into the screen with the tableview still visible in the upper half of the screen. I've seen some apps doing this neat effect before but I don't see on how to accomplish this.
Anyone some helpful hints on this ?
I did this a little while back and asked about it.
I ended up doing exactly what the highest voted answer says: Put the UIPickerView in the same View as your other items and animate the sliding motion using UIView's beginanimation method.
Add a done button in your tool bar. Add a new target/action to the button to call a method on the UIViewController that has your table view and picker controller. Then have it animate the view back off the screen using a UIView animation block.

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).