dynamically change UIImageView x-position in auto layout - ios

I have a custom table view cell with UILabel and UIImageView that designed with constraints. I want to set the UIImageView x-postion as after label end. So UIImageView x-postion will change periodically.
How I handle this situation? even I set the frame in coding which doesn't change while Autolayout.

Related

Change value of UILabel inside UIStackView in .xib file

I am creating a vertical UIStackView inside a UIView and placing UILabel elements inside it.
Now, I want to change the height of Label inside the UIStackView. But the height property seems to be disabled.
Alternatively, I am able to set height constraint for the label and change it's value programatically. I want to know if there is a way to change the value in the XIB itself as my purpose is to set a static value and cut down on adding code for it.
First add UIView in UIStackView and Then Add UILabel under view. Set label's constraint. Now you can just change the UIView Frame from Size inspector, it will automatically change the label frame.

iOS - Make UIImageView resize to fit UILabel with AutoLayout

I'm having this issue since quite some time now and it's driving me crazy: I have a UILabel with text that can be dynamically changed, and I have a UIImageView that should act as the text's background. I would like the UIImageView to resize itself to always fit the UILabel's text.
"Paid" could become "Free", or "Payant" in French for instance, and the box behind should always resize.
Using Storyboard, I have tried adding a UIImageView with the UILabel on top of it, and setting the constraints of the UILabel to the UIImageView, but this ends up resizing the UILabel to the UIImageView's size. I cannot set a fixed width or height for the UIImageView because it should adapt.
My second try was to make a UIView, recategorize it as a UIIimageView, add the UILabel as a subview, make the UIView resize to the UILabel and add the image programatically but once again, no success.
What is the right way to do this?
For the first method, I assume you set the had the label and the image view have the same vertical and horizontal centers as well has the same height and width. The problem is the layout engine is assume the intrinsic size of the image is more important than the label. To change that you need to change hugging priority and the compression resistance of the views. Go to the size inspect of the label (picture) and increase the hugging priority to required. This will for it's height and width to be it's intrinsic height and width. You could also decrease the image view's compression resistance, so it is more amendable to being sized down.
The constraints for the label:
You can change the top and leading to place it in the appropriate spot in the view.
The constraints for the image view:

iOS UITableViewCell dynamic sized tableview cell with imageview and label

In my app i have a UILabel and a UIImageView under each other. Both of them have a fixed width, but their height supposed to change.
I want the UILabel's height to change to fit the text it's holding and i want the UIImageView's height to change automatically to fill the width and keep it's aspect ratio.
My problem is that autolayout doesn't allow me to have both item's vertical content compression resistance priority to the same constant. Because of this one item will always oppress the other.
What i expect is the tableviewcell to change it's height dynamically to fit its content.
I do not want to modify anything from code.
You can do it in alot possible way like
1.) Using StackView here is a link to help http://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views
2.) You can select your UILabel and its superView than select aspectRatio , in a same way select your UIImageView and the superView than select aspectRatio.
It will help Thanks.

Resizing UIImageView based on UITableViewCell content height using autolayout constraints

I have a UITableViewCell xib with below view:
As shown it has below components:
UILabel - dateLabel
UILabel - addressLabel
UILabel - criteriaLabel
UIImageView - separatorImageView
Since I want to increase the height of cell based on contents in the labels, I added below constraints to each:
So dateLabel constraints are:
addressLabel constraints are:
criteriaLabel constraints are:
Without adding constraints for separatorImageView, cells appear like this:
ie. cells are resizing based on content which is perfect :)
Now problem is - if I add below constraints to separatorImageView:
Cells start appearing like this:
Please suggest which constraints shall I add to separatorImageView so that it resizes as per the height of cell without affecting proper resizing of cell.
Maybe this is not the best answer but for special cases I do this:
create a UIView named resizingVIEW, pin it to top, bottom, trailing, leading of super view (contentView)
remove separatorImageView Bottom Space Constraint
ctrl+click from separatorImageView to resizingVIEW, select equal height
(NOTE set resizingVIEW background color to clear color/ or hide it)

Change viewController's height as textView height changes

I have a viewController with a textView inside a scrollView in the viewControllers view. The textViews scrollEnabled feature is set to false and I have the textView height resizing as text is entered. This works perfectly until the textView height becomes larger than the viewControllers view height. I have the view height set to freeform and know you can set it to a different height. However, I have other objects int the view and want the view to load with its initial default height and then to resize as the textView height changes and then the user can scroll as that height changes.
Is this possible?
it's not clear what you are trying to do, but if you want to know more about UITextView an it's delegates, you need to study how UITextView works:
UITextView *textview
It's already a UIScrollView, it inherits from UIScrollView, right? and UIScrollView inherits from UIView.
You need to know that a UITextView is a special view with properties like frame (from UIView), contentOffset and contentSize (from UIScrollView).
And in the inheritance you have all the delegates for UITextView (UITextViewDelegate), for UIScrollView (UIScrollViewDelegate). Inside those delegates you have a lot of methods to determine some of the information you want to know.
But, I don't understand what do you need anyway.

Resources