0

I have a parent view which has so many child views most of the child views size are fixed except three labels.

so these three labels height can differ according to its content.

I want to change the parent view height when these label height changes and I want to change the position of other views whose that follows the label.

I think when I assign the label some contetn I should read its frame and get the height and I should change the postiion of following element according to that and I should change the parent view height according to that.

I want to do this the right way

Please let me knwo the right way to do this

Update:

what I'm trying to achieve is kinda like below image and it has so many fields like this

enter image description here

Shankar Naik
  • 401
  • 5
  • 16
  • UILabel has intrinsic size. UILabels take frame based on the content and u need not do anything about it. Show us the image of what u need u can achieve it with Autolayout constraints – Sandeep Bhandari Sep 18 '17 at 10:48
  • Is there any specific reason you are not using a table view? – Swapnil Luktuke Sep 18 '17 at 11:26
  • @lukya - I don't get it .. table view is when we have same item repeatedly right ! I just have couple of textboxes and labels .. some textbox act as picker like that..Please correct me If I am wrong – Shankar Naik Sep 18 '17 at 15:23
  • @SandeepBhandari - I have label whose height autoincreases that works fine .. but I have to change Parent views height based on how many rows of content label accomodates.. The approach that I have mentioned above seems tedious and I am not sure if that is the best way to handle this – Shankar Naik Sep 18 '17 at 15:25
  • @shankar-naik : Please add image of what are u trying to achieve its very difficult to imagine what are u trying to achieve – Sandeep Bhandari Sep 18 '17 at 15:26
  • @ShankarNaik , no table views are not for a list of **same** items. You can return any cell at any index you want. Your UITableViewDatasource gives you full control over what you can display. UITableViewDelegate lets you interact with the cells the way you want. In fact, if you are using storyboards in your project, (and if possible, i suggest you should,), you can directly create **static table view cells** in your table and directly use them like normal outlets on your UIView. – Swapnil Luktuke Sep 18 '17 at 15:52
  • @lukya - Please have a look at the above image .. basically If I want to show validation message I can show the message and find the height and change the row height according to that .. or is there any other better way to do this ... height handlign things.. this where I get tricky .. because some field would have satsfied validation so ... no valiation will be shown .. and some fields will have validation message of one line and some will have validation message of two lines or 5 lines – Shankar Naik Sep 18 '17 at 17:20
  • so row height has to be calculated based on how much the text is gonna occupy the validation label.... if there is any other bettre way to handle this height thing please let me know or is it possible tablecell row can auto adjust based on its content – Shankar Naik Sep 18 '17 at 17:21
  • @SandeepBhandari - Please find the attached image – Shankar Naik Sep 18 '17 at 17:22
  • 1
    1. You **can** easily do this with table view. 2. Shifting your views to show validation messages in between your fields will lead to a very bad user experience. You have some multi-line validation messages. Imagine items on your screen suddenly moving down when you tap or enter. 3. Instead, reconsider showing all the validation messages below all your controls, or highlighting all the wrong fields but showing "Please fix these issues : " and only a limited number of messages (say 2) at once with total/remaining count of 'wrong' inputs (like "and 3 more issues") etc. – Swapnil Luktuke Sep 19 '17 at 10:46
  • @lukya - Thats what I intend to do.. so every table cell now will have three items .. label ... textbox ... label third one is goign to be validation message . If I hide validation message I want row height to increase .. if i hide validation message I want row height to reduce ... the validation message will be shown just below the control ... so how am I supposed to do that ? can you give me some tips on how can I handle this ? and if the validation message is one linek .. row height has to change for just one label .. if lines are two .. the row height has to change accordingly – Shankar Naik Sep 19 '17 at 19:03

0 Answers0