Autolayout Imagesize should increase as per UItextview Text - ios

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.

Related

How to set UIButton which has title and an image to change the width, according to localisation

I have following button configured.
and this is how I configured it. it works fine with English.
I have setup localisation with my app and when new text load to button it looks like below
Note : I have setup fixed width constraint using autolayout for the button and relation to
Greater than or equal.
how to fix this. hope your help with this.
Handling Insets for having button and image displayed together is a pain to adjust. A more common approach would be:
Create a custom view
Add an image and label giving appropriate constraints within the custom view
Put a button on top with clear background color so as to make it transparent.
All the three views can should be children of the custom view.
Now using this custom view, you have the flexibility to adjust it as per your needs.
Hope this helps :)
You can fix this issue by adding a new UIImageView as a subview to the super-view of the UIButton and set the image. Add the constraints leading(to the trailing of UIButton), centreY(to centerY of UIButton), height and width(constant you like) constraint to the UIButton that you already have. And add a UITapGestureRecognizer and set the action provided for UIButton.

How to make UITableViewCell resizable with EasyPeasy?

I know there was a lot of questions about it. But, I have problem with this anyway. I have UIImageView that needs to have specific size and UILabel that needs to have dynamic height. I want to show label on the right side of image. I try not to use storyboard, so here is how I gave constraints using EasyPeasy library:
myImage.easy.layout([Top(8), Left(20), Width(95), Height(95), Bottom()])
myLabel.easy.layout(Top().to(myPicture, .top), Left().to(myPicture, .right), Right(), Bottom())
Below is the result:
As you see, when the text is big, it doesn't fit in cell. I set numberOfLines as zero for label. As I've understood, my image defines the size of the cell and the label can only cover the area that it actually can have. So, what can be the problem? How to solve it? How to make label's height resizable, despite image height? Is order of constraints important?
I don't know exactly how EasyPeasy works but I think you should use something like this:
myImage.easy.layout([Top(8), Left(20), Width(95), Height(95), Bottom(>=0)])
myLabel.easy.layout([Top(20), Left().to(myPicture, .right), Right(), Bottom(20), Height(>=90)])

Constraints making UITextView smaller

I just put constraints into my ViewController, and I set the UITextView so that it keeps its height and width, yet at runtime it shrinks to only cover the text inside of it. How can I avoid this?
Thank you!
In my opinion, at the run time, the size of your TextView has changed because of the content, I mean the text set to it. To prevent this kind of issue, I would suggest some options which will be regarding your UI
At first, if you intend to fix size of the TextView, so from the constraints or Interface Builder, please create width and height constraints then fix the value. For example
If you wish your text view will be dynamically in size based on contents, you can set width and height values are greater than or equal a minimum value as it will not break your UI
I hope this would be helpful.
I assume you're using Interface Builder. Check the value for Content Hugging Priority that IB set for the text view. If it's too high, it may be overriding your constraints.

How can I change the height of a button with Swift?

Depending on the height of the screen, I would like to adjust the height of a button in a view. What is the easiest way to do this in Swift?
I tried it in this way and also with CGRectMake() but nothing changed:
self.myButton.frame.size.height = self.myButton.frame.size.height*scrOpt
How can I "update" the frame?
The reason why you see no changes may be because you're using AutoLayout, and the button has some constraints applied to it, and you need to change the height constraint to accomplish what you want.
Edited: Changing frame properties directly seems to be possible in Swift but was not possible in Objective C.
If you are using auto layout, you need to update its height constraint, else update its frame
NSLog(#"%#",NSStringFromCGRect(self.myButton.frame));
NSLog(#"%f",scrOpt);
self.myButton.frame = CGRectMake(self.myButton.frame.origin.x, self.myButton.frame.origin.y, self.myButton.frame.size.width, self.myButton.frame.size.height*scrOpt)
NSLog(#"%#",NSStringFromCGRect(self.myButton.frame));
Edited check this and see what is Print NSLog

Set height constraint for UITextView

I'm fairly new to iOS development and am having a hard time sizing a UITextView to it's content. I've found several examples of calculating a strings render size and/or updating the frame size of a textview, however I can't seem to get those to work.
When I add a UITextView to my view it adds a Height constraint which I think is locking it to a specific height. How can I work around it, update the constraint via code, and/or get my UITextView to resize vertically to show my content?
You can create an outlet to the vertical size constraint, and then adjust the .constant property of the constraint to amend the height of your text view.
A UITextView inherits from UIScrollView. As part of it's logic, it changes the height of its contentSize property to allow the user to scroll vertically to any portion of the TextView's content.
I would recommend using the ContentSize property of your UITextView to figure out how "tall" your content really is. You can then set the frame of your UITextView accordingly.
OR: You could figure out the size of your text using the right method from the NSString+UIKitAdditions category.
If you don't want autolayout then disable it in the xib file.
If you want to change the contraint and it's value this tutorial will help you to deal with autolayout.

Resources