set first text on UISearchBar - iphone

i want to set first text on my UISearchBar -the text is "Search"-, and the text will disappear when user start typing.
just like this:
how it could be.???
thanx

use placeholder property to set your grayish text that get disappears while text is written on it
searchBar.placeholder = #"Search";

[self.searchBar setPlaceholder:#"search"]

that's the placeholder text, you can set it in Interface Builder, or programmatically with UISearchBar's placeholder property

Related

Swift: How to "append" image to my text in uitextfield

I would like to append an image to my text in uitextfield, and since the text in the textfield is never consistent I cannot use rightview. Any suggestions?
P/S: I used a textfield instead of label because tapping the textfield is supposed to trigger a picker view.
Ahh, after scratching my head for the entire day, I ended up hide the text in my text field and add a uiLabel on top and an imageview beside it with autolayout and update the text.

UITextView don't show text

I have a TextView in my xib file.
After I assign text for it, it doesn't show the text till I double click it, and actually change the selection of the text:
Before double click:
After double click:
After changing selection size:
Do you have any idea, how to show text from the beginning?
Thanks
We found the solution. This situation happens, when you try to update the txt before the view is visible.
We override the function viewDidAppear, and did this code:
// To fix the bug of not showing text in textView
self.txtViewShowDetails.text = nil;
self.txtViewShowDetails.text = self.mediaItem.mediaDescription;
[self.txtViewShowDetails setContentOffset:CGPointZero];
If the view is animated, or inside animated controlView, we have to call the viewDidAppear after animation finished.
I had a similar bug, but it happened when I made the text unselectable. Once I made it selectable again(checked in nib), it fixed the text again. While this isn't a solution to this bug (unless making it unselectable also fixes your problem), hopefully it will help others.
think you have set TextView custom font in IB .so you need to set custom font in code.Please set system font in IB and check in both device
TextView.font=[UIFont fontWithName:#"HelveticaNeue-Medium" size:17.0];
In my case text was long and it was trimming from end. I was setting text first then font and colour. I Set font first then text. It works for me.

UISearchBar Placeholder besides another Text

How to put a placeholder text besides the text entered by user in the UISearchBar Text.
Or even to put some text in gray if the above cannot work.
You can make gray texl as UILabel and put it on UISearchBar as subview.
Or you can write your own class, subclassing UISearchBar with this functional.

how to assign a color for particular text in xcode

How to assign a color to the particular text. i don't want to use the textview.
Thanks
If you don't want use neither UITextView or UILabel you have to create your how view to display the text.
In this view you have to get the context, set the color and then display the text with the function:
CGContextShowTextAtPoint

UITextField does not show the assigned string

In my project (my first one) I try to assign a text to a textfield created in the Interface Builder.
[date setText:#"2010"];
I also tried using
date.text = #"2010"
I have created the Outlet and don't get any error... the text just doesn't show up.
Just in case it matters...
I prevent the keyboard from showing up and display a calendar instead (works).
Any idea what could be wrong?
Could it be a problem that I'm using delegate methods on the textFields to prevent displaying the keyboard?
If you don't want to edit text using a keyboard, then what is the use of UITextField?
Instead of using UITextField you can use a UILabel (as a global variable) to show the text and use a custom UIButton without a title and use its action for showing the calendar view. You can change the text of the label whenever you want in that class like viewWillAppear or viewDidAppear.