How to add UI Objects (Image) to a UITextView or UITextField? - ios

I would like to achieve something like the following for a UITextField or a UITextView.
The Object added to will be treated like a string when we delete texts.
I know I can add a backgrand image and get it done with too many codes.
Please let me know the best possible way to achieve this and kindly give me some pointers.

I would recommend you use Text Kit. Using a UITextView with Text Kit allows you to define exclusion paths (which could be used to form text around subviews) or to add attachments into the text directly.
Here's another answer that gives some pretty good direction: How to wrap text around attachments using iOS7 Text Kit?

Related

Format UILabel with image and links

How can I add a string with link and image in a UIlabel using swift code.
Below is a sample what I needed:
Visit to the following link Terms and conditions 💼 for specific
instructions.
I need the Terms and conditions and the bag in red collar and remaining text in grey color. Tapping on red coloured text opens a link.
Anyone please help.
The short answer is, don't do that. A UILabel displays a string. That's what it's made to do. Adding images and links to a label is stretching it well beyond its intended purpose.
You can take a generic UIView and add subviews for your text and your image(s). Build your desired contents out of the elements you need.
I would suggest using a UITextView since that supports clickable links. Set it's editable flag to false and turn on link detection.
As per your problem described here. I have found a perfect solution, as per your requirement.
Here is the link to your solution : Link
You can try this and bridge it as it's written in Objective-C
KILabel
I solved it by adding an attributed text and user interaction to handle link tap. To add image NStextAttachment can be used. Write method to handle tap gesture for label using range.

iOS how to insert UITextField inline within UITextView

Is there a way to insert text inputs inline inside a block of text? I need to allow users to input some data inline within text. I thought that I would be able to use NSMutableString with attachments, but it seems to support only UIImage as attachments.
This is an example of what I'm trying to achieve:
Thanks!
You should take a closer look to CoreText which gives you a very fine grained access to text layout. But anyway, this is a difficult task. You may create a HTML-Page with input fields and display it in a WKWebView, which should be much easier to implement.
If the text is static, create a custom UIView class, and position the UILabel and UITextView controls. This is the only possible approach.
If the text is dynamic, you can make use of Auto-layout concept along with the above approach.

Is it possible to 'hyperlink' text within a UILabel/TextView but activate a segue on tap of this 'hyperlink'?

I say 'hyperlink' because I don't know what else to call it, and that is how i'd like it to appear.
Obviously this is possible using a combination of labels and buttons, but my labels and buttons are programmatically generated and I imagine i'd have to also programmatically arrange them, which would likely be tedious and inflexible in terms of changing font sizes etc.
Any ideas/approaches would be much appreciated!
As an example, look at Instagram's following and news feed:
You should set userInteractionEnabled and then add a UITapGestureRecognizer to the label.
Have a look at Nimbus Attributed Label it can provide the functionality you are looking for.

Corona SDK - native textfield within scrollview?

In Corona SDK, I'm looking for an example/tutorial of something that seems like it should be incredibly basic: including a text input field within a scrollview.
I have been using widget.newScrollView() for the scrollview, and native.newTextField() for the text input field. The problem, of course, is that the "native" objects exist outside the Corona display object hierarchy, so the textfield can't be placed inside the scrollview and scrolled that way.
A comment on this Corona Labs blog post suggests the technique of using a placeholder image that looks like a textfield, with a touch listener that overlays the real textfield when the user touches it. Is that the best approach to take?
"Faking it" is a proven method of getting stuff done when programming, whether you're using Corona SDK or anything else. While it's nice not to have to jump through hoops to get something done, sometimes it's just the best way to handle it.
In this case, I think using a placeholder is probably the best way to go. You could create a function that uses display.newRect to create the frame of the fake textfield and then display.newText to put in the default and/or user-supplied text.
Something like:
local dObj = showFauxTextfield(x, y, width, height, str)
Create the rect and text according to the parameters passed in, put them into a display group, and pass that back to the calling code. You can then put that into your regular display group along with everything else.
Inside showFauxTextfield() you'll create an event handler that pops up a native.newTextField when it's touched.
It's a little extra work, but Corona typically saves you a lot of dev time anyway, so you'll probably still come out ahead. ;)
If you aren't keen on implementing the placeholder technique mentioned in this post you could always use the WidgetCandy library (http://www.x-pressive.com/WidgetCandy_Corona/). It includes a text field class that will provide similar functionality.

How to detect and make hyperlinks/mentions/hashtags clickable in UILabel?

How to detect and make link/mention/hashtag clickable in UILabel. Alternatively, is there any open source library that I can utilize (I already looked at Fancy UILabel which doesn't handle multiline tex, TTAttributedLabel which doesn't handle mention/hashtag)?
There is no way to do so with UILabel in the current iOS...
TTTAttributedLabel will let you style up your label, however for clickable (or rather - tappable) links you should rather either use a UIWebView and style it in such a was as to disguise it as a Label, or, you could get geeky and split your labels up and use a UIButton in the mix, but that's very messy - like a puzzle, only... they don't fit together.
Last option you might have is to overlay a UIButton over a link, but this requires that you know where the link is and since the question was about detecting links etc...
You should really look into UIWebView.
You can achieve this using following library:
https://github.com/SebastienThiebaud/STTweetLabel

Resources