Multiline label with different font styles and IBActions - ios

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?

Related

How to format a text like bold/italic in UITextField in Swift iOS?

Here consider this image. I have taken a toolbar with icons for text formatting. After selecting that sentence if I hit B (bold) it should be bold. Even I need that too if I select bold then further text to be show as bold. Consider this textbox UITextField. Incase you have some good reference like github you are welcome. I have already spend two days in a row in SO but not get any proper solution. One bold function is enough for me.

Custom iOS keyboard - Custom font output

I am trying to create a custom keyboard using the app keyboard extension. I am happy with the layout but the output is depended on the UITextField's font.
Is there a way to force a different font (use special characters?) while using the keyboard ?
Thank you
It depends.
Text field (or any other view that draws text) uses 2 informations on how to show some text. One is the sequence of characters called String and the other one is how the string should be represented. The second one is then split it things like fonts, colors, line height, line breaking and wrapping...
So the keyboard alone is not enough to for instance present a certain part of word using different fonts. You need at least a bit of access to the item that represents the text. So if you have no access to your text field then the answer is; No, you can not fore a different font when using different keyboard.
If you do have the access then the answer should lie in NSAttributedString. It is a string you can assign to most items under attributedText. This class wraps your raw string and can add many properties to parts of text you want to change. That includes using a different font.
Another approach would be using HTML tags. Again you will need to process this using for instance NSAttributedString or display it with another element like web view.
I would try it with using NSAttributedString. Hook up to delegate and implement textField(: shouldChangeCharactersIn: replacementString:. The implementation itself may still not be easy though.

Create edittext like stackoverflow tag text box

I want to create a multi lined edit text that can hold buttons but also have the ability to add free form text.
It should behave like the tag text box of stackoverflow that is under the body of the question when you ask a question on stackoverflow.
I thought about one layout that holds buttons (e.g. tags) and an edit text right after said layout. But as I want it to be multi-lined and if there was a line break, I'm not sure how the edit text should behave, since it couldn't be a quadratic box anymore.
Can you point me in the right direction? I've seen a post about making parts of an edittext uneditable. I could do this and put buttons over it, but the buttons might be a little bigger than the underlying text.
Do you know of alternatives?
I hope you get the point, if not I'll draw the control.
You can achieve same by using FlowLayout. Keep on adding text/button view it will automatically wraps contents to next line

iOS, textView half editable

I need help in string formatting in iOS UITextView. I have a textView, for now it`s editable. Now I want to add a few strings. they should be like header and user must be able to type only under it, and when he press ENTER or DELETE line sting should change their position, so at the end it should look like
Header 1(with color not editable)
/* user can type here
*/
Header 2 (with color not editable)
/* user can type here
*/
I think i need to use delegate and attributed string or something,
but I can`t figure it out. HELP please
The best way to achieve this is to make two labels and two text views on top of a scroll view. like
The heights of two text views can by dynamic depending on the text length. And in this case you can avoid endless IF conditions as you would need to put everything in a single Text view.
The advantage of this approach is the label text format will be very easy to set, you can simply set the attributed string in the storyboard.

How do I set the style of the current paragraph in a UITextView?

I am writing an iPhone/iPad application that requires simple word processing capabilities. I'd like to give users the option to add styles to the current paragraph. For example:
Type several paragraphs into the UITextView
Put the cursor in the middle of the second paragraph
Press a button that says "center" or "ordered list" or something
The entire paragraph takes on that style
After reading through the documentation I can't figure out a way to do this without starting at the cursor, reading backwards to a line break, then reading forwards to the next line break, and recording that as the range. Then style the attributedText property. Is that the only way to do this?

Resources