nslayoutconstraint

Evenly Space UIViews of equal sizes in superview using Auto Layout in iOS 6

风格不统一 提交于 2019-11-28 11:29:49
问题 I am in a need of having the series of buttons to be evenly placed in superview Horizontally using Auto Layout. Here, I want to keep the sizes of the subviews same, only the center of the subviews will be placed in such a way that there is equal number of space between them. Note: I dont want to set the Size of the superview, I want every thing to be Auto Layout-ed. Please Help, I am stuck !! Thanks!! 回答1: You can create as many UIView 's as you have buttons, and center the buttons inside the

UICollectionViewCell dynamic height with autolayout

一曲冷凌霜 提交于 2019-11-28 11:09:47
I am using auto layout with UICollectionViewCell. So the idea is to allow CollectionViewCell to determine it's size based on layouts. All the constraints are set properly but the problem is that I can not calculate it's size for data source method collectionView:layout:sizeForItemAtIndexPath: Ideally I would like to calculate Cell's height doing the following: static MyCell *myCell = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ myCell = [[MyCell alloc] initWithFrame:CGRectZero]; }); cell.model = model; [cell updateConstraints]; [cell layoutSubviews]; return cell.frame

Set constraints through code to an element from Storyboard with swift iOS8

偶尔善良 提交于 2019-11-28 09:58:10
问题 I have a ViewController with a tableView. I've set it up in the Storyboard. Is there a way to set the constraints for the tableView programmatically? I've tried to set a IBOutlet from my tableView in the ViewController and added constraints to it. But that didn't work. This is my ViewController import UIKit class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad()

Autolayout: origin and size should change according to width and height factor

落花浮王杯 提交于 2019-11-28 09:55:20
Here is a scenario what I needed. I have put a UIButton on IB (size iPhone4 inch) whose initial frame on IB is x:100,y:100,w:100,h:100 . I want the origins and height should change according to device size. for example the width and height of iPhone6 is 375X667, hence the width factor (375/320=1.1718) and height factor (667/568=1.1742) . In this scene I want to change my buttons origin X and width with multiply by width factor (1.1718) and origin Y and height with multiply by height factor (1.1782) . In this case my button should be shown on x:100X1.1718, y:100X1.1742, w:100X1.1718, h:100X1

_UIButtonBarStackView: breaking constraint when becomeFirstResponder sent

拜拜、爱过 提交于 2019-11-28 07:30:47
When jumping from one textfield to an other, get this: translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x6040002806e0 UIKeyboardAssistantBar:0x7f986d40d020.height == 0>", "<NSLayoutConstraint:0x60400008ece0 _UIButtonBarStackView:0x7f986d4041c0.top == UIKeyboardAssistantBar:0x7f986d40d020.top>", "<NSLayoutConstraint:0x60400008ed30 UIKeyboardAssistantBar:0x7f986d40d020.bottom == _UIButtonBarStackView:0x7f986d4041c0.bottom>", "<NSLayoutConstraint:0x60400009f220 _UIButtonBarButton:0x7f986d438480.height == UILayoutGuide:0x6040005b5ee0.height>", "<NSLayoutConstraint

When should translatesAutoresizingMaskIntoConstraints be set to true?

人盡茶涼 提交于 2019-11-28 04:59:23
I've read the documentation . But I'm still not sure when I need to not set it to false . In the code below if I set it to false I won't see the header at all. If I leave it as true , then everything is fine. The following in View debug hierarchy will give a warning " width and position are ambiguous". func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header = UIView() header.translatesAutoresizingMaskIntoConstraints = false header.backgroundColor = .orange header.heightAnchor.constraint(equalToConstant: 10).isActive = true return header } I thought

What happens with constraints when a view is removed

。_饼干妹妹 提交于 2019-11-28 04:14:07
The question I have is simple but I couldn't find any information in the documentation. What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)? For example, let's have container C with subviews A and B . Container C holds some constraints. Then we call [A removeFromSuperview] . What happens with the constraints for A ? What then happens if we add A to C again? The constraints are removed. If you add A again, you will have to make new constraints for it, or if you save the constraints before you remove A, you can add them back. When I do

Width and Height Equal to its superView using autolayout programmatically?

久未见 提交于 2019-11-28 02:53:36
I've been looking for a lot of snippets in the net and I still can't find the answer to my problem. My question is I have a scrollView(SV) and I want to add a button inside scrollView(SV) programmatically with same width and height of its superview which is scrollView(SV) so that when user rotate the device button will have the same frame of scrollView(SV). how to do the NSLayout/NSLayoutConstraint? thanks MadNik If someone is looking for a Swift solution – I would create a Swift extension for UIView which will help you each time you want to bind a subviews frame to its superviews bounds:

NSLayoutConstraint crashes ViewController [duplicate]

柔情痞子 提交于 2019-11-28 02:53:26
Possible Duplicate: presentViewController: crash on iOS 6 (AutoLayout) I'm getting this error when clicking on a button in my app: 2012-06-28 21:43:36.860 AppName[2403:707] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *** First throw call stack: (0x3568788f 0x37a2e259 0x35687789 0x356877ab 0x333a254d 0x333a26bb 0x333a2423 0x33333001 0x332a13c7 0x3317ec59 0x330f4c17 0x330ff267 0x330ff1d5 0x3319e59b 0x3319d367 0x331f86a7 0x8fb11 0x355e13fd 0x330d6e07 0x3319c5e7 0x355e13fd 0x330d6e07 0x330d6dc3

iOS change auto layout constraints when device rotates

房东的猫 提交于 2019-11-28 02:51:01
I want to modify the layout constraints when the device rotates. My UIViewController is composed of 2 UIViews , in landscape they are horizontally aligned, and in portrait they are vertically aligned. It does work actually, in willAnimateRotationToInterfaceOrientation , I remove the desired constraints and replaced them with others to have the right layout... But there are problems, during rotation auto layout starts breaking constraints before willAnimateRotationToInterfaceOrientation is called, so where are we meant to replace our constraints when the device reorientation occurs ? Another