nslayoutconstraint

NSLayoutConstraint in swift

送分小仙女□ 提交于 2019-12-06 17:07:40
问题 I am trying to convert the following code to Swift: leftConstraint = [NSLayoutConstraint constraintWithItem:self.contentView attribute:NSLayoutAttributeLeft relatedBy:0 toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; [self.view addConstraint:leftConstraint]; Can someone give me the new syntax to do it in Swift? 回答1: Copy & paste from the documentation: convenience init(item view1: AnyObject!, attribute attr1: NSLayoutAttribute, relatedBy relation: NSLayoutRelation

UIView Element Layout Constraints

馋奶兔 提交于 2019-12-06 11:27:19
I'm fairly new to iOS development but have reached the point where I want to create my own composite UIView as a custom UIButton. I would like to layout a UILabel and 2x UIImageViews as follows; But I would also like to anchor the controls (subviews) in such a way that as the label expands, due to translations say, the view automatically handles the extra real estate. For example; Ideally - the right hand side UIView is anchored to the right; and remains a fixed width/hight (right aligned). the label and bottom image divide the remaining left hand space the label is vertically centered in the

How to change height of UIView that already has height anchor?

半世苍凉 提交于 2019-12-06 11:21:32
If I have this for a child view controller: autoCompleteViewController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ autoCompleteViewController.view.topAnchor.constraint(equalTo: view.topAnchor, constant: 0), autoCompleteViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0), autoCompleteViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0), autoCompleteViewController.view.bottomAnchor.constraint(equalTo: googleMapViewController.view.topAnchor, constant: 0), autoCompleteViewController.view

UITableView with self sizing cells becomes jerky when calling deleteRowsAtIndexPaths

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 11:05:00
I have a UITableView with self sizing cells. Table contains 1 section and some rows. I have some rows say 30 and I want to delete row during didSelectRowAtIndexPath . When I delete a row available near the bottom of tableview (say 28th row ), the rows before 28th row changes their position and it causes jerky animation as a result of deleteRowsAtIndexPaths . See attached gifs for more details. Cells constructed with frame deletion animation Auto Resizing cells Deletion animation - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(CGFloat)tableView:(UITableView *

UITableViewCell doesn't use autolayout height when using insert cell into table

这一生的挚爱 提交于 2019-12-06 10:26:09
问题 Background I use purelayout to programmatically create my UITableViewCells, following the instructions here, which basically states that you gotta set the top/bottom constraints on a cell, then use self.tableView.rowHeight = UITableViewAutomaticDimension; to get it right: Problem Everything works fine, except when I insert a new row into a tableView. I get this effect: https://youtu.be/eTGWsxwDAdk To explain: as soon as I click on one of the tip cells, the table is supposed to insert a driver

How to handle NSLayoutConstraints with screen size/orientation changes in iOS 8/Swift?

萝らか妹 提交于 2019-12-06 08:38:18
How to work with IB Constraints and NSLayoutConstraint ? I want to programmatically fine-tune my Interface Builder Storyboard layout, as I can't achieve desired layout with constraints in Interface Builder alone. The iPhone 4S and iPhone 6 Plus are particularly challenging for my iOS 8 layouts. Questions: How do I find screen dimensions when the UIViewController appears? How do I detect orientation changes & resulting screen dimensions in iOS 8? How do I modify layout constraints programmatically? How do I deal with IB size classes programmatically? Maybe by "weighting" components in IB, I

Updating existing constraints does not work, wrong use of .active property?

陌路散爱 提交于 2019-12-06 07:45:15
I have a storyboard that contains : A "tab bar" on the left with 5 tabs A container on the right side of the tab bar that contains 6 image views that share the same space so it looks like this : Each image view is configured to occupy 1/3 of the container's width and 1/2 of its height. However, different ratios can be provided at runtime (from a JSON file) so that for example, the 1st image view's height become 70% of its container's height and 50% of its width (therefore, the 2nd and 3rd image views widths occupy 25% of the container's width and the 4th image view, 2nd line column 1 has a

Resize current view using NSLayoutConstraints

☆樱花仙子☆ 提交于 2019-12-06 07:20:10
I'm trying to set the layout of a view using NSLayoutConstraint s. I can set things up within the view correctly, but I also need to be able to resize the current view (the one that I'm setting the constraints for) if the constraints require it. In other words, I want to set a fixed content size with a flexible window, rather than the reverse. So basically, I have: NSDictionary *views = [NSDictionary dictionaryWithObjectsAndKeys:self.v1, @"v1", self.v2, @"v2", nil]; // Set horizontal constraints [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[v1]-|" options:0 metrics

Subclassing NSLayoutConstraint constant based on screen height

Deadly 提交于 2019-12-06 03:43:26
I have a project with a Tab Bar, and a custom Navigation bar for each of the tabs. Each of the Navigation bar UIViews have a height constraint constant set in the storyboard. I would like to subclass this NSLayoutConstraint (for the Nav height), so that it changes the height for iPhone X. The Navigation bar needs to be much taller on an iPhone X, and since I'm not using "out of the box" objects, my constraints need to be manually set. Essentially, I want to do something like the following in the subclass, so I don't have to repeat a bunch of code and make unnecessary outlets: override func

UILabel size calculated incorrectly when changing font in UILabel

一曲冷凌霜 提交于 2019-12-06 02:49:35
问题 I am adding a UILabel to a view with the following layout requirements: The label should be centered The label should have a maximum font size of 100 points, but should scale down to fit. It should not truncate. The label's height should not exceed 450 points. Another view will be positioned directly below the label. My label's properties layout constraints seem to describe this adequately: let label = UILabel() label.backgroundColor = UIColor.yellowColor() label.font = UIFont