Height Value of Rect Transform cannot be changed via script

I have a scroll view and contains child objects arranged in the form of grid layout, using grid layout group. This is the sample image of my grid layout.
73814-error2.jpg
The pic images and the texts are generated at run time using prefabs and script. The image and text are included in a single game object and converted into a prefab. The list is populated at run time from a server. The parent game object of these prefabs has a grid layout group and content size fitter is added to it.


Now coming to the problem, since there is content size fitter, the text in the last 3 images is cutoff and cant be viewed properly. I need to increase the height of the content rect transform a little bit more so that the bottom most text is also view able properly. But the height can’t be edited due to content size fitter. I tried to obtain the height using the code:

float height = imageContainer.gameObject.GetComponent().rect.height;

but it was returning 0 only. The vertical fit of min size is disabling the height value. Can someone please help me in this issue.

You should try to use something like this :

imageContainer.gameObject.GetComponent<RectTransform>().offsetMin = new Vector2(rectTransform.offsetMin.x, newBottomValue);
imageContainer.gameObject.GetComponent<RectTransform>().offsetMax = new Vector2(rectTransform.offsetMax.x, newTopValue);

Where offsetMin.x is left, offsetMin.y is bottom, offsetMax.x is right and offsetMax.y is top.

Seen here : http://forum-old.unity3d.com/threads/setting-top-and-bottom-on-a-recttransform.265415/