nslayoutconstraint

Swift Constraints in Subclass

大憨熊 提交于 2019-12-12 03:44:23
问题 I was wondering if there was a way to access constraints from a subclass. I have a custom view. I'm not sure if I can access the constraint I already have set in the UI, so I tried just creating the constraint from the subclass itself. class PerformanceView: UIView { func initialize() { let heightConstraint = NSLayoutConstraint(item: self, attribute: .Height, relatedBy: .Equal, toItem: superview, attribute: .Height, multiplier: 0.47, constant: 0); superview.addConstraint(heightConstraint) } }

How to fit tableview to superview below navigation bar via storyboard autolayout

旧巷老猫 提交于 2019-12-12 03:17:09
问题 I want to create a scroll disabled tableview which will fill the view below navigation bar. Finally I've managed to do it but it's not the right way because I'm giving minus 64 margin (status bar + navigation bar) to tableview. I'm assigning my constraints from storyboard. I've tried lots of other constraints with the table view like giving zero constraints from 4 sides or equal width + equal height + center horizontal + center vertical none of them worked. What is the right way to solve this

Identifying and fixing auto layout issue from log output

半腔热情 提交于 2019-12-11 17:21:35
问题 I'm preparing a multi device information focused iOS app almost exclusively in interface builder storyboard. I'm using table view controllers with text or other content into static table view cells. In specific cells, I want a grid of text fields with the same height rows but various widths - depending on the length of the text field. I'm using a vertical stack view that contains horizontal stack views, all with Alignment: Fill and Distribution: Fill Proportionally. If I do not reduce the

Does it matter which superview I add constraints to?

余生颓废 提交于 2019-12-11 15:39:22
问题 Let say I have 3 views A|----------| | B|-----| | | | C ▢ | | | |_____| | |__________| If I have a constraint involving view B and view C. The documentation suggests adding to view C would be illegal: The constraint must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used

Trouble with UIScrollView and Constraints

▼魔方 西西 提交于 2019-12-11 11:47:48
问题 I'm having trouble with UIScrollView and Constraints . I want to display a FAQ inside my application. This will include several questions and answers, with various length. It won't change after launch, so I handle everything directly in the storyboard. However, it has to work on different iPhone screen size (from iPhone 5 to iPhone 6 Plus). So what I'm trying to do is : UIView UIScrollView UIView (FAQ1) UILabel (Question 1) UITextView (Answer 1) UIView (FAQ2) UILabel (Question 2) UITextView

UITextView Alternative

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:35:56
问题 As i understood from Apple docs attributedText property of UITextView: This property is nil by default. Assigning a new value to this property also replaces the value of the text property with the same string data, albeit without any formatting information. In addition, assigning a new a value updates the values in the font, textColor, and textAlignment properties so that they reflect the style information starting at location 0 in the attributed string. Therefore i cannot add an

Xcode - Adding constraints to UITableView so that it fits all screen sizes

依然范特西╮ 提交于 2019-12-11 09:24:55
问题 I've read quite a few tutorials and watched numerous videos on using constraints in Xcode. For some reason, I'm still missing certain aspects that are necessary to make the user interface look the way it's supposed to for all screen sizes. Currently, I have a UITableView laying on a view controller. The view controller is set to "Inferred" size and I have all of the different sized devices open in Assistant Editor Preview to the right so I can view the changes. I've encountered multiple

Center Label Based on View

好久不见. 提交于 2019-12-11 04:26:41
问题 I want to center a label based on a view. The label is inside a collectionView and I want to center this label based on a view that is NOT inside the collectionView at runtime . What I tried to do is change the constant of the label's constraint to the view's frame midY but it doesn't work: // THIS DOES NOT WORK. I want the `textLabel` centered inside the `yellowView`. cell.textLabelCenterYVerticalConstraint.constant = yellowView.frame.midY Here is the screen: Here is the Storyboard: This is

Enumerating a view's NSLayoutConstraints in Swift?

让人想犯罪 __ 提交于 2019-12-11 03:06:38
问题 [self.view.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop) { if ((constraint.firstItem == view) && (constraint.firstAttribute == NSLayoutAttributeTop)) { constraint.constant = -200; } }]; In Objective-C, I would be able to enumerate a view's constraints and adjust the constraints accordingly, but in Swift I'm having difficulty figuring out to do the equivalent. here is my attempt at applying the code in swift: for (index, value) in

How to get NSLayoutConstraint's identifier by Its pointer?

十年热恋 提交于 2019-12-11 02:52:43
问题 I setup in Storyboard identifier for each constraint: Now I get error with unsatisfiable constraints . I try to debug this by printing constraint's pointer: po 0x17db78d0 Now to order investigate what constraint it is, I would like to print its identifier just like: po 0x17db78d0.identifer. ...but it is not working. I get an error: error: hexadecimal floating constants require an exponent error: 1 errors parsing expression Hence, how to print identifier for specific NSLayoutConstraint ? 回答1: