I need to make text within a UITextView to be clickable. Basically I want to show more information on the text being clicked on. In PHP I would surround the text I want clickable in square brackets and then make anything in square brackets a link (i.e. [More Info]). How can I do something similar in Swift? I know I can turn on data detectors to detect http links but I don't want http showing.
Related
I know xlsxwriter has a write_url function, and I know about setting formats and how to make the text of that url blue. In this case my urls point to other cells in the same spreadsheet. However, I'm wondering if xlsxwriter has a way to set the color of the url such that it will change color once it's been clicked, like the usual blue when unclicked and purple when clicked, for example like Google does with search results you have previously visited.
I know openpyxl has a way to do this, with the builtin 'Hyperlink' style or creating a Color object with theme=10. Is there a way to do this in xlsxwriter?
Is there a way to do this in xlsxwriter?
Not currently. If you open a feature request I can look at adding it.
A perfect example of what I am trying to do is the Instagram comments.
Suppose we have a user and a list of text (the comment). I want my UIView to have the username in some font style and clickable along with text next to it and wrapping around to the next line (which is not clickable).
It might be easier to understand if you just look at this:
Notice how the username is clickable and separated from the text, but the text wraps around to the next line. How can I do this?
Is it possible to add a text link into a TextView? I want the link to perhaps behave like a button, where I can assign an action to it.
EDIT: When I say assign an action, I mean actually giving it something in the code. I'm wondering if it's possible to dynamically add a "button" into text that I can assign a coded action to.
Live scenario
Think of something like a dictionary app. Maybe the definition of one word uses another word that you might not know the definition of, so being able to click on that word to instantly search it rather than having to type it in would be a nice user friendly feature. It seems rather unlikely, though, I guess.
I would recommend using NIAttributedLabel from Nimbus, an open source iOS library. You can specify text ranges that are links, and you get delegate messages sent when a user taps on it.
Main Nimbus site: http://nimbuskit.info/
NIAttributedLabel docs: http://docs.nimbuskit.info/interface_n_i_attributed_label.html
in the inspector, go to the Text View Attributes tab then make sure "Detect Links" is checked.
Yes you can. Add the URL into the text view, then open up the Attributes Inspector. You will see an option in there to detect links.
I know of a way, but its a LOT of work. First, you have an NSAttributedString that you have the text view display. Second, attribute the range of text you want to be the button. Third, assign a tap gesture recognizer to the text view and in the method called by the recognizer, you'll use core text to determine if the tap happened over the range of text that represents the buttons.
Heres how youll use core text: create a framesetter with the attributed string. Create a frame from the framsetter with the shape of a square that is the frame of the text view, inset by the padding of the text view. The frame will allow you to get the y origins of every line in the text view and and once you know what line the tap happened on, you can use the line to then figure out exactly what character was tapped on that line by giving it an x offset. Once you know character index on the line, you can add it to the beginning of the range of the line and get the index of the character within the whole string. Then you can check if its within the range of the text that is your button. If it is, you can then call a method to simulate a target action type behavior.
Ive explained the process of how to accomplish this and specified what kinds of core text objects youll need, ill let you look up the specific api details:
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CoreText_Framework_Ref/_index.html#//apple_ref/doc/uid/TP40005304
You can also use my objc core text wrapper:
https://github.com/mysterioustrousers/MYSCoreText
What about CoreText? It Can draw many kinds of Text .
This question already has answers here:
UILabel - string as text and links
(6 answers)
Closed 9 years ago.
I want to allow my users to include a tappable element in a paragraph of text they've written inside my app. Similar behaviour to this is a twitter client which has tappable links and mentions as part of the text. I presume the best way to do this would be to use an NSAttributedString. I'm unsure how I could get some of the text to be tappable though. How could I do this?
you can use a UIWebView and pass in an html string,
<p>Some text going here <button> clickable text </button> more text <\p>
and there is a delegate method for when a uiweb view sends out some request for clicking the
button
you can record the location of the text you want to click and then manually test if the user taps in that area
you can pragmatically create custom buttons as you see fit and place them in the places of the words
best way to do it in general is the uiwebview which html already has text formatting , but i don't know how complex your app is so that might not be an option
I am using the corona sdk to create a list of items in a tableview, once and item is selected I then display a bio for that item, and also want to display an image.
I can do this fine, but how can I right align the image in the body of text and get the text like flow round the image? I am using native.newText to display the text.
Similar to having a right aligned image inside a tag in HTML.
You cannot do that automatically, you need to detect the image dimensions (I suggest using myImage.contentBounds ) then place the text near it as you wish.
In a app of mine we display a picture, some basic data, and a detailed description, what I do is put the picture, then place the basic data to its right, and then place the detailed description below both.