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

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.

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.

how to add button in label text

I don't know if this is applicable in iphone. I'm trying to add button inside label text. See image below.
If you see there is href or anchor(web name) inside the square that I'm pointing. Can I put button inside the text? These data came from rest api. I need an advice if this applicable or possible to do that. If ever this is applicable please give me idea on how to do that.
Thanks in advance
I think what you want is actually add user interaction to certain range of the string, right?
This can be easily achieved by this library TTTAttributedLabel
Please take a look at it and then you can dynamically set what you want to link.

iOS Add Image to TextField

I am experimenting a little bit witch apps programming.
How I can add a UIImage to a UITextField"?
Like Whats App or the most other Chat Apps.
I have search some time but doesn't find a solution, also i have tried to search in side of XCode with the auto complete but I have not found a function. So I hope you can help me.
The easiest way to add an image to a text field is to have a UIView that contains both UITextField and a UIImageView as subviews.
Next up, you can have a UIButton with both an image and text, and just set userInteractionEnabled to "NO" and it'll behave like a text view with an image next to it.
Now to get more complicated, if you want a chat-like text field that allows text (that you can type into) and images next to each other, you need to start thinking about custom subclasses. Other people have asked and have gotten answers for this same approach.

Is it possible to customize a text field , in iOS?

i am in need to use a text field in my application but the ones provided by XCode are only 1 line long and you can only change the width but not the hight.
I was wondering if its possible to make it look more lines long?
Is it only possible with customization and if yes any good tutorials?
Thank you!
First off, you can actually change the height of a UITextField. Just change the border style in the Attributes Inspector to anything except the default "rounded corners". You can then resize it right in Interface Builder. If you really wanted to, you could even change it back in your viewDidLoad method like this:
self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
However, to have multiple lines, you have to use a UITextView. It's by default multi-line, but see the Apple documentation for more information.
You can use a UITextView. The document about it here. If you need something else, please post an image of what you want to achieve.

UIScroll and its nested elements

I created a UIScrollView.
I set up the dimensions and then I am trying to add UILabels.
However the labels are all white text (annoying because I have to change the property per label).
Is there a way to make all labels (new ones that are dragged from IB to the view) have a default text color of black?
Edited to match comments
I want to use IB as much as I can. Therefore I want to drag UILabel from the Library palette to the UIView. When I do this, the UILabel is set to white (default). I want the default color to be Black. I know I can do this programatically but I am trying to avoid that unless I really really need to.
There's no easy way to do exactly what you want. But what you can do is create a label with the properties you want, store it somewhere on the drawing board but not in the view, then duplicate it each time you want a new label instead of dragging on a new one. You can duplicate easily using option+drag.
I think the short answer is "no, there's not an easy way to do what you're describing."
The easiest way I can think of would be to create all your UILabels (with the default setting of white text), then control-click them all and set their text color all at once – all the other ways are less convenient, or would essentially require that Apple open-source Xcode or UIKit so that we can get at their internals.
Yes, there is a way. You could loop the subviews of the target view such as:
UIView * targetView;
[...]
for(id subView in targetView.subViews){
if([subView isKindOfClass:[UILabel class]]){
[subView setBackgroundColor:clearColor];
}
}
why do the labels have to come from the object library? You could get the functionality that you want by dragging only one UILable from the library to your view set all the properties to the defaults that you want and hit copy(command+c) once. Now you can paste(command+v) your UILabel with the special property values as many times as you want, IBActions and outlets will also be retained in the copys.
If you plan to tweak more involved properties than font color and size, then I would suggest a more custom approach that will require only minimul coding before you do the bulk drag and drop work in IB.
Subclass a UILable in Xcode, set all of your properties just once in a simple return method and than call this method from both "init" and "awakeFromNib" Now go back to IB and do all your drag/dropping making sure that the labels are of your subclass.
However, it is my opinion that if you are doing this a lot, especially if you will be doing something similar again in the future, you will save a substantial amount of time and energy to implement this "label factory" in code. Its likely less code than you are imagining it will be and the kicker is that you can reuse it in the next app. anyway thats my 2cents, Good Luck

Resources