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

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.

Related

Change position of sub view under a text view based on the text views content swift

How could I️ achieve a similar effect to Twitter’s tweet view, where the location label position changes based on how much text is inputted. For instance
When there’s no text, the location label is right under the text view but when text is inputted, the label changes its position:
How could I️ achieve a similar effect in swift?
See this StackOverflow post regarding fitting a UITextView to the content of its text.
In the UITextView shouldChangeTextInRange delegate call, update the frame of the UITextView to fit the text. Then update your location labels frame relative to this new UITextView frame.

Add More Button in UiButton

I have a long string to show on UIButton. I want to show the first 2 lines and if the text is longer than that - add a More button that will pop up an alertview to show the full text. See the image
What is the best way to do that?
Add your more button and wire it up the standard way, but set it to hidden. Then determine the length of the string and see if it is bigger than your textview. If so, set the more button to visible. When the button is pressed resize the textview and add more lines.
I'm not around a Mac at the moment so don't take this answer as gospel.
I would think that if you added a UILabel as a subview of a UIButton and setup the label to only show two lines before truncating, you could then detect if the displayed text was different than the actual text you used when you created the label by using NSString's isEqualToString: method. If the strings are different you know the label is truncated and you should show the 'more' button. I found this code on StackOverflow that returns an NSString within an arbitrary NSRect.

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 write text on selection indicator of uipickerview

how to write text on selection indicator of uipickerview
The simplest approach will be just to add UILabel with your text over the UIPickerView. You only need to find the right coordinates so text will be placed well.
If you want to display text on it try adding a UILabel as a subview to the view containing the picker. You just need to get the frame in the right spot - easy with IB, more trial and error through code. The set label to have a clear background. Just update the label value as needed.