I have an ViewController that has a title, an image and long text. I want it to be scrolled as a whole not the only text.
I am calculating the size according to its text. It is calculated correct but, I tried with that code.
newsDetailTextView.heightAnchor.constraint(equalToConstant:newsDetailString.height(containerWidth: newsDetailTextView.frame.size.width)).isActive = true
Its size does not change.
What might be the wrong?
Could you please indicate me the way?
BR,
Erdem
Set scrollEnabled property of textView to false or uncheck via storyboard.
I recommend you to read here if you want use a constraints way.
Check the Apple's official documentation in Listing 13-1 where used heightAnchor.
Related
I have been trying to achieve following layout in autolayout
I want to acheive this
may be i am doing something wrong due to which i am getting following result.I get this
can anyone correct me ?
This kind of layout is easily accomplished by using UIStackView, Please use UIStackView either in storyboard or in code.
Please check Apple documentation on it
https://developer.apple.com/documentation/uikit/uistackview?changes=_6
If you are using storyboard for Textfield then simply give leading and trailing to Textfield. Dont give the fixed width to textfield, it will work for all devices.
Same logic if you are setting textfield programatically. Dont give fixed width
As said above, use your element inside a horizontal stackview. Unfortunately, if you’ve a iOS target iOS 9.0, you will have to use another trick. Your stackview will become a normal view which will contain your elements to align. After that, you can the element width to be equal to their superview with the multiplier use.
Per example if you have 3 elements inside your view but you want that the first one being larger than the two others by setting the multiplier with a certain ratio like 2:4 for the first one and 1:4 for the last ones :-)
I have a need to set the contentSize of a non-scrolling UITextView exactly to it's superview's frame. I need to do this for the purpose of getting the range of characters that fit, and while I know there's better methods for doing this, or even better views to be using, I need to use this custom UITextView for it's specific capabilities. Simply doing:
textView?.contentSize = superView.frame.size
doesn't seem to set anything, and it's contentSize is still as long as it's content. I want to simply truncate the content at where it just wont fit anymore. I'm on Swift 3 and xCode 8 if that makes a difference.
You can do so using .bounds:
textView?.bounds = superView.bounds
That should set all the properties you want to be the same as the super view.
Figured it out. Scrolling was enabled. Disabling scrolling seems to have fixed it.
I have a UITableView that contains 4 custom cells in different sizes.
For some reason, the UITableView's scrollView isn't stretching "outside the view and then automatically returns to the maximum position", it's just stops on the maximum position and doesn't stretches.
I have no idea why, can anyone help me?
Thank you!
If by stretching you mean "bouncing", then you should check the bounces property and set it to true:
tableView.bounces = true
Usually it's set to true by default, so you have probably disabled it somewhere in the code.
I a using Autolayout to implement in iPAD and want to perform task like as per my Textview text the Image set behind set as per Text. Like this:
But could not set proper constraint for it.
Can anyone suggest what to do for it to make it perfect ?
You can set as following :
If It'll not work then remove and add another TextView and set as i suggest.
I think, It'll helps...
You can set equal height constraints for the Imageview and Textview.
For textview, you can set the background image rather than keeping a separate imageview behind the textview. Then the image will be resized as the textview size changes.
I want to change the height according to content of cell. I don't want to calculate height every time for each text. This should also work for any with of text means label should update on its orientation change also.
Is there any feasible way to do this?
Please refer link below. This is the best way to do exactly what you want.
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout