Swift iOS 8+ UISearchBar icon, placeholder, and text centered - swift

By default, the placeholder and icon of UISearchBar are left aligned. I want them to be centered like so:
On click of the search bar, the search text should also be centered.
I don't want to use offset because the alignment should dynamically change based on the length of the search text and the width of the phone. For example, if the UISearchBar has been clicked but no text is entered, the icon should right be in the middle.
Is there any solution - preferably not using offset - to center the search bar icon, search text, and placeholder?
Thank you

Don't use a UISearchBar, in the context of these kinds of customisations. You'll have to make your own using a UITextField and a UIImageView, and responding to the delegate calls.

Related

marquee like UITextField

How to create marquee like UITextField in Swift. I want to use it in a iOS controller where the user can click on the textfield and select a location, the text is longer enough that I need to implement the marquee Textfield, The text should scroll from right to left.

iPhone UIButton provide different inset values for highlighted state

I want my titleLabel text move a little down on button tap (i.e. I want to give different inset values for highlighted and default states).
I have custom button background images and the button goes down in highlighted state image but the text on it stands at the same place so it gives a bad effect and looks like the text is seperated from button.
Is there any way to solve this?
Thanks in advance
The easiest way to do this is to put your text on the button's background image.
If you can't do that for some reason you can try to add IBAction on Button down and adjust button.titleLabel.frame.

Iphone custom cell keyboard overlaps

i have a TableView with custom cells that i have built with Interface Builder.
Inside the cell, i have a label and a text field. But when i click on the text field to write, the keyboard overlaps the text field and i can't see what i am writing.
How can i avoid this?
Thanks
You have to resize the view containing the tableview when keyboard is shown. The way you can do is discussed here,
How to make a UITextField move up when keyboard is present?
You can search in Stackoverflow more on 'iphone keyboard hides textview'.
after resizing view, you can scroll table to the current cell too.

How to disable select functionality in UITextView?

I want to create a text display area (either UILabel or UITextView) in my iPhone app which (1) allows scrolling and (2) does not allow selection. I have tried the following techniques unsuccessfully:
Basic UILabel: Didn't allow
scrolling, and clipped text to the
bottom of UILabel space on screen.
Giant UILabel within a UIScrollView: the UILabel kept placing the text (vertically) at the center of the giant UILabel, so it often was outside of my UIScrollView.
UITextView: So far this approach has worked the best, because it scrolls and does not clip the text. I can even subclass UITextView to enable resizing the text to fit within the textview, and passing any touch events to the superview to detect taps & swipes. But, when the user taps and holds on the text itself, the text selection interface appears. I am not interested in this interface and it actually is distracting from the user's experience. I have tried to subclass canPerformAction:withSender:, but apparently this function is called after the tap event--not before it.
Does anyone know how to disable the text selection interface in UITextView, without also disabling scrolling?
Take option number 2, but set the numberOfLines property on your UILabel to 0. This will set the number of lines to 'unlimited' and prevent the vertical centring of the text.
Don't forget to set the lineBreakMode property to UILineBreakModeWordWrap so that your text doesn't run off the side of the UILabel.

How to make UITextView look like Facebook login?

How can I make my textfields look like the Facebook login screen?
alt text http://img688.imageshack.us/img688/4162/photocr.jpg
That's really a UITableView. You can put some UITextFields without a border inside a couple of UITableViewCells.
I'm extremely late to the party - but this library makes this sort of UI much easier: https://github.com/escoz/QuickDialog
Use a grouped table for your UITableView (i.e., UITableViewStyleGrouped) with one section and two rows. Then put UITextFields in the table cells (you may have to make custom table cells) and set the placeholder property to whatever text you want to display before the user types somethings.
It might be a UITableView, but then again it could be just a UIView with rounded corners and two UITextFields and a separator line.
I believe you're asking how to style UITextView, not how to setup a UITableView, so what I would do is create a .PNG image that's mostly white with two little rounded corners up top. Flip the image vertically and you have the one for the bottom. Drag both to your resources folder in XCode, then open up Interface Builder with the .xib. Set the background color to your blue. Click on the text field, go to Inspector and select the image you just created in the Background field. Do it again for the other field. You can use the Placeholder field to create the gray "Email" and "Password" placeholder text.