nslayoutconstraint

What's with Constraints in SwiftUI?

坚强是说给别人听的谎言 提交于 2019-11-30 17:33:57
What is happening now with constraints in SwiftUI ? Do View types adapt automatically for bigger devices etc. or what should we have to do instead? RIP, Constraints! SwiftUI doesn't use layout constraints. UIKit is still around, it's not deprecated and fully functional, so if you continue to use the classic approach, you can use as many constraints as you wish. However, if you choose to go with SwiftUI → rest in peace, constraints! The core concept to align views with each other is using stacks: HStack VStack If you want to overlay views (i.e. put one view on top of another), you can use a

What's with Constraints in SwiftUI?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 16:41:35
问题 What is happening now with constraints in SwiftUI ? Do View types adapt automatically for bigger devices etc. or what should we have to do instead? 回答1: RIP, Constraints! SwiftUI doesn't use layout constraints. UIKit is still around, it's not deprecated and fully functional, so if you continue to use the classic approach, you can use as many constraints as you wish. However, if you choose to go with SwiftUI → rest in peace, constraints! The core concept to align views with each other is using

Autolayout constraints warning “Will attempt to recover by breaking constraint”

一个人想着一个人 提交于 2019-11-30 14:06:39
问题 I am setting some specifics constraints for iPhone 4 when the app is ran on this device. Everything look great in terms of alignment and everything. But, I am getting an error for all my constraints that is trying to recover them by breaking the constraints. This method gets call in my viewDidLoad when it detects if its an iPhone 4 - (void) addConstraints { // removing automatic system constraints [self.view removeConstraints:self.view.constraints]; [self.view

iOS - Find top constraint for a view?

蓝咒 提交于 2019-11-30 13:11:39
问题 I am trying to find the top constraint of the view in code. The top constraint is added in storyboard, and I don't want to use an IBOutlet. Logging the value of the firstAttribute in the following code seems to always return a constraint of type NSLayoutAttributeHeight. Any idea how I could reliably find a top constraint of a view in code? NSLayoutConstraint *topConstraint; for (NSLayoutConstraint *constraint in self.constraints) { if (constraint.firstAttribute == NSLayoutAttributeTop) {

UILabel text not automatically resized using Auto Layout

微笑、不失礼 提交于 2019-11-30 12:35:07
I'm trying to implement a constrained UITableViewCell subclass and everything is working perfectly, except for the UILabel . The constraints that I've set up are definitely being enforced, but the text inside of the label does not resize to a smaller font size when the constraints clash. Instead, the height of the UILabel gets truncated and the font remains the same size, meaning the letters get cut off at the top and bottom. Is there some method I have to call in order to get this to work? I would think Auto Layout would be smart enough to automatically resize the font size, so I'm kind of

Creating Auto Layout constraints to topLayoutGuide and bottomLayoutGuide in code

◇◆丶佛笑我妖孽 提交于 2019-11-30 12:22:27
问题 Apple's documentation on creating Auto Layout constraints between a view and one of the layout guides only shows an example using VFL. Is there any way to create these constraints programmatically without VFL (using NSLayoutConstraint's other API or similar)? (Note: I'm specifically asking about doing this in code, not in Interface Builder. And I don't want the calculated length of the guide set as a static constant on a constraint, I want a constraint where changes to the layout guide length

How is it possible that UITableViewCellContentView height is different from heightForRowAtIndexPath:

痞子三分冷 提交于 2019-11-30 11:57:20
问题 I'm facing a really weird problem on my UITableView. I have some different cells that I want to display on a newsfeed-like table view. And I have a problem with a cell after reuse. The cell contains two images, two labels and a view with the share/like/comment buttons. I'm gonna try to draw it, but I'm not sure it's gonna be pretty : ------------------------------------------------- | | __ ____________________________ | | | |_2| | | | | | | 3 | | | | | | | | 1 | |____________________________|

Autolayout Error with UITableView

怎甘沉沦 提交于 2019-11-30 11:38:47
I have a TableView and I specify the height for each cell using the delegate method tableView:heightForRowAtIndexPath: . When I rotate the view I get this error that I don't quite understand. It can't satisfy the constraint below and breaks it to continue. "<_UIScrollViewAutomaticContentSizeConstraint:0x8e8d040 UITableView:0x9423400.contentHeight{id: 213} == -1568.000000>" Does anyone know what is happening and why I'm breaking this constraint? UPDATE : This issue is no longer relevant in iOS 8, which adds support for self-sizing cells. It is still relevant for iOS 7 however. Original answer

Update height constraint programmatically

我的梦境 提交于 2019-11-30 10:43:01
问题 I am new in auto layout. I have done all of my project from xib file, but now I faced a problem where I have to update an view's height programmatically. I have tried below but now working. [[self view] addConstraint:[NSLayoutConstraint constraintWithItem:loginContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:loginFrame.size.height]]; In console it's shows Unable to simultaneously satisfy

“Width equals height” constraint in Interface Builder

妖精的绣舞 提交于 2019-11-30 10:16:52
问题 I can't find a way to create a 'square' constraint, meaning 'width equals height' in Interface Builder. I guess it's possible to add such constraint programmatically. Is there something I can do in IB? Maybe I just don't see it? It seems trivial, yet I can't find it. 回答1: Update Xcode 5.1b5 Ctrl+click and drag from a view and release while the pointer is over the view. Select "Aspect Ratio". It will create a constraint where the first and second item is the view. Before Xcode 5.1 You can't