Dynamic height and view more capability for objective C - ios

I am trying to display facebook feed from a json object on a uitable view. I am using a uitextview for displaying the text. How can i add the view more/Continue Reading capability which is common on the facebook app for larger text as shown in the picture below

Check out
- boundingRectWithSize:options:attributes:context: (reference) as a way to get the size of the text you want to display. If the bounding rect is larger than the amount of space you have available you'll know you need to display your 'continue reading' button. Tapping the button could cause the cell to redraw with a larger height, based on the size of the bounding rect you calculated.

Related

iOS: How to display a box of 'tappable tags'

My use-case is like this:
The user defined some tags (text like "#asdf", "#qwerty", "#let_me_think_about_it" and "#decide later"). I want to display these in a box without scrolling (and don't know, how many tags the user created until I display the box).
The box itself should not be scrollable at all but be shown in a UITableViewCell (which is being scrolled). So it must compute the proposed height and respond to Autolayout mechanisms. If a (ARM) Mac user resizes the window to be smaller than before (or an iOS user rotates the device), the box should increase/decrease its height, as necessary (within the limits of Autolayout, since I know of some issues). Each of the tags should be (de)selectable at the same time (UILabel with UITapGestureRegognizer attachted?) and be able to displayed 'selected' (via a background view).
So, the box should primary try to align all content horizontal. If There's not enough horizontal space, do a "line break" and continue on the next "line".
My current solution is a UIScrollView that the user can scroll horizontal and tap any of the (UILabel) views. The displayed views itself are being loaded from a NIB file, like a UITableView does. The issue here is that not any of the selected tags might be visible at the first glance.
If there was no Autolayout, I'd exactly know what to do. But since there it is, I want to use Autolayout in my NIB files and wonder what you would do?
(How do you compute the required width of such a view and decide when a line break is to be done (and how?))
I think I need a simple hint. But if it needs code to explain, ObjC and Swift is both acceptable. :-)
So, the box should primary try to align all content horizontal. If There's not enough horizontal space, do a "line break" and continue on the next "line".
This sounds like a job for UICollectionView with UICollectionViewFlowLayout. You can disable scrolling, and the layout object will tell you the size of the content so that you can adjust the size of the box.
(How do you compute the required width of such a view and decide when a line break is to be done (and how?))
If you're doing it yourself, you add up the widths of all the items on the first line, and if it's larger than the available space, you move the item that extends past the limit and any subsequent items to the next line. Repeat as needed. But that's exactly what a flow layout does for a collection view, so there's no need to roll your own.

Adjust UILabel position up based on previous UITextView content?

I want to make an bubble view design more or like WhatsApp design. Please check the attached WhatsApp screenshot,
In screen Time label (1.12 PM and 5.16 PM) adjusts its Y position based on text message content. Its adjustable based on last line content (if the last line is not fully filled, its moves up slightly and it reduces bubble height - looks good).
Is there any solution/suggestion? How to know, Is UITextview content takes fully last line or any other way to achieve this?
Thanks!

Let image if nil disappear in swift 3 (or shrink so it looks like it disappeared)

I am quite new to developing.
I am currently working on a clone of Instagram to learn the basic stuff.
Currently I have a fin working app with all the upload, like and fav details, Instagram offers.
Now I want to do the following:
I have one screen where you can choose a pic (but don't have to) and a caption.
If the user decides to post no pic and maybe just a couple of lines (like a joke or some interesting stuff or riddles), the uploadedImage in my cell - which is empty and optional then) - disappears and the whole cell shrinks to fit the content.
I will upload 2 pictures so you can understand better how to do it.
Do you know how and where to let the image if nil for this cell disappear? All posts should be displayed on the same cell and fitted properly.
Thanks, I hope I said it clearly.
This is also the feed but now with a post without image, where the UIImageView is blank. I want the empty image to disappear for this reusable cell, so that it shrinks and has no white space
This is how the post should look like if the user decides to post a post without picture. They all should use the same reusable cell
ups can only attach 2 pictures as my reputation is too low, I could send the 3rd via chat if you need it, it shows the cell as it is in Instagram (copied) The pic 1 shows the cell and where the blank space is is usually the uploaded picture
thanks :)
If you use a Vertical UIStackView for your content, constrain it to the top and bottom of the contentView of the tableView cell and set the tableView to use UITableViewAutomaticDimension then the stackview will calculate its intrinsic size from the size of its children (and the imageview will contribute 0 hieght when its nil). the tableView cell will then resize to always be proportional to the height of the image.

How to change the TableView Cell row Height and font based on Settings in IOS Text View Size

Hello I am building an application where I wanted to change the application font based on the settings from IOS. As given link below.
http://www.imore.com/how-increase-or-decrease-font-sizes-iphone-and-ipad-ios-7-dynamic-type
I wanted to know if there is anything that needs to be done.
Currently on changing the Text size to smallest or largest my application remains on the same font and hence the Table View cells , UI View screen labels remain as it is.
Any help is much appreciated.
For Font you can use SystemFontSize to get current iOS font size. This link may useful to you which i followed - http://tirania.org/monomac/archive/2013/Sep-25.html

how to implement the autoresizing UITextView vertically?

First look at the screenshot:
second press the return button, the screenshot for your reference:
after four times click
return
button, the height of text field will not be higher any more.
now here is the question: how can I implement the function of textfield? and what about the background Image behind the text Field , should auto resize too? if there are any solution, let me know! thanks very much----
Make it UITextView not a text field, track the text changes at shouldChangeTextInRange of the textView delegate.
In this method calculate the number of lines (textView.contentSize.height/textView.font.lineHeight), compare it with the previous value to decide whether you need to proceed or just return. If the number of lines is changed, check whether the textView is already displaying the maximum number of lines (that must be 3 on the image) and based on the results you will change the textView, it's superview and a button frames (you can also make it animated easily) and probably scroll the text to the change region with scrollRangeToVisible.

Resources