How to change height of ImageView through nslayout? - ios

I have ImageView. In Storyboard height of ImageView = 45. I need to change height = 70 programmatically. How can I do this?

Double click on the constraint to highlight it, make an IBOutlet of the constraint in your header file of your controller and change the constraint's constant value as you please.

Related

Missing constraint for connecting view.top with dynamic height uilabel bottom

I am trying to arrange 3 views - 1. Image view with fixed height and width 2. Textview with fixed width but dynamic height and 3. Tableview with fixed width and height adjusted according to available space after textview.
What constraints I am missing here. Why I need to give Textview or Tableviews Y pos or height constraint. Doesn't it make their height fixed?
You have to put a height constant to your textview. Because autolayout can't figure out how many pixels to give to your both view.
If you want to adapt your height depending on the text, you can use :
TextViewHeightConstraint.constant = [TextView intrinsicContentSize].height
into your code after your link your constraint via iboutlet.

UIImageView won't change size

I am trying to alter the width and height of an UIImageView object but for some reason I can't.
This is the code I used:
-(void)setMenuImages
{
self.menuImageButton.image=[UIImage imageNamed:#"myimage.jpg"];
self.menuImageButton.frame=CGRectMake(0,0,20,150);
}
What am I doing wrong? The (UIImageView) menuImageButton is not created programmatically, but from storyboard interface with initial leading, trailing, width and height constraints.
You can self. menuImageButton.translatesAutoresizingMaskIntoConstraints = false in viewDidLoad and remove their constraints or you can add those constraints as IBOutlets and change them like
self.imageWidthConstraint.constant = 20;
self.imageHeightConstraint.constant = 150;
UPDATE
To declare constraints in your header file you need to select those constrains and right click drag to the .h file as show in the gif

ios: Change the height of UIImageView with constraint inside UITableView

in my app i am working on UITableView in which i am using UIImageView by setting up constraint on storyboard to display image. All i need is when there is no image available the height of ImageView will become 0 otherwise if image available height will be 150.
Try adding constraints to left, top, right. Add a IBOutlet in your viewController for NSContraint for height. And when initialising cell check for image is available or not. Depending on that set the IBOutlet value.
Add that IBOutlet to your height constraint of UIImageView.
Set TableView cell height to automaticDimensions.
Let me know if it helps or having any issue.
In storyboard
Set your imageView constraint height <= 150
in heightForR0w
return UITableViewAutomaticDimension
in estimateHeight
return 200
Give your ImageView to FixHeight Constraint
Create IBOutlet of that FixHeight Constraint
#IBOutlet weak var imgviewHeightConstraint: NSLayoutConstraint!
in your cellForRowAtIndexPath
check this way
if image available {
cell.imgviewHeightConstraint.constant = 150
} else {
cell.imgviewHeightConstraint.constant = 0
}

iOS position UILabel in circle view

I defined a view which contains an UImageView and a UILabel. I setted constraints for each elements.
In wanted to do a circle with the first view, so I did that in the code :
self.mainView.layer.cornerRadius = self.mainView.frame.size.width / 2;
self.mainView.clipsToBounds = YES;
So it works, I have a circle, BUT the UImageView and the UILabel seems don't follow the constraints setted in the storyboard.
For example, on my UILabel, I setted a margin left and right 5px to the mainView, but I can see my UILabel "out" the mainView....
I tried to do a "setNeedsUpdateConstraints", but it's not the solution.
So, what I need to do to have my UILabel correctly positioned ?
Thanks,
I think this is what you are looking for:
self.mainView.layer.masksToBounds = YES;
Your problem is that when changing the mainView's layer you are not actually changing the bounds of the view. The bounds of the view are still represented in a rectangle manner. what you need to do is change the width constraint of the UILable.
To do so just create a autolayout constrain to your UILable (is you don't have it already). Control-Drag it to your viewController and change it dynamically using the constant value in the constraint.
If you don't need to set it dynamically just set the left & right margins to a bigger margin

UIIView Inside UITableView Change Frame height to 0 or 60

I have a UIView in top of UITableView (drag and drop in storyboard . I tried to hide and show that view. but table view stands in place . how can i change frame of uivew so when it is invisible tableview goes all the way to top?
PS. I will provide more info for those who are willing to help. Thanks in Advance
http://i.stack.imgur.com/cM3tA.png
![the view with hamburger button and textfield)
With autolayout:
Add height constraint to your UIView with button and textField
Create Referencing Outlet for this height constraint (lets count it will be "searchViewHeightConstraint")
Add Vertical Spacing Constraint between the UIView and the UITableView
In code - when you need to hide UIView - just set its height constraint to 0
self.searchViewHeightConstraint.constant = 0.f;
Also you need to store somewhere the initial height of the UIView (when it is visible) and set its Height Constraint to this value when you need to show UIView.
Without autolayout:
Save the value of UIView frame height
Set the height of UIView to 0
Decrease the y-coordinate of UITableView frame with saved height of UIView
CGRect tableViewFrame = tableView.frame;
tableViewFrame.origin.y -= viewInitialHeight;
tableView.frame = tableViewFrame;

Resources