nslayoutconstraint

UITableViewAutomaticDimension not working in Xcode 6.3

筅森魡賤 提交于 2019-12-09 08:01:14
问题 I updated my Xcode to 6.3 along with Swift 1.2, and I made the transition. Everything works except dynamic row height for table view. I have those on 3 completely different table views, so it probably isn't something else influencing the bug. I set all of the table views to: tableView.rowHeight = UITableViewAutomaticDimension and all of my xib files are properly constrained. Any ideas? 回答1: I simply added UITableViewAutomaticDimension to estimatedrowforindexpath as well. You can see how it

changing constraints at runtime in swift

冷暖自知 提交于 2019-12-09 03:46:37
问题 I'm really very weak in constraints part of ios. I have gone through many reference link as shown below but still not able solve my issue. Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one In case , i need to change the y-axis of UIView2 based on some condition. The storyboard.png shows the layout. If condition fails UIView2 with step1, step 2 and step3 should be visible and it's position should also change as shown in condition1.png If condition pass UIView2

How to get constraints from UIView Programmatically

时光毁灭记忆、已成空白 提交于 2019-12-08 19:21:03
问题 I want get UILabel constraints from UIView but I can't get any constraints. I set the constraints in CustomView.m like this: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _titleLabel = [UILabel new]; [self addSubview:_titleLabel]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *titleLabelBottom = [NSLayoutConstraint constraintWithItem:_titleLabel attribute

NSLayoutConstraint SIGABRT on iPad

你离开我真会死。 提交于 2019-12-08 11:53:06
问题 Application is made in Interface builder. Seperate storyboards for iPhone and iPad. Project runs and works properly on iPhone Simulator, iPad Simulator, iPhone 4 with newest iOs, but I get this error when I build it on 'new iPad' spring 2012 with iOs 5.1. Fix/explanation? 2012-12-12 16:44:16.763 LNG[397:707] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *** First throw call stack:

How to add a CAGradientLayer to a UIView when using programmatic constraints

戏子无情 提交于 2019-12-08 07:16:42
问题 For an iOS app in Swift, I am using programmatic constraints and would like to add a CAGradientLayer() to a UIView(). Below is my code which doesn't work. import UIKit class ViewController: UIViewController { let animationView: UIView = { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false return view }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(animationView) setupAnimationView() animationView.addGradientLayer() } func setupAnimationView() {

iOS Constraints on Grid of Equal Width/Height Buttons cause positioning and size to vary

前提是你 提交于 2019-12-08 05:13:53
问题 I'm updating my Calculator app to use new dynamically sized buttons and having a problem with the constraints. The contains should work fine as far as I can tell, but Xcode complains about misplaced views. The values it gives for the misplaced views are not proper and if I try to fix them, then it just causes more views to be "misplaced." In the screenshot below, the first multi-colored row (orange, green, pink, yellow, red) is a row of UILabels. They should all have equal widths with 0

What exactly does lowering the priority of a constraint do?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 04:28:37
问题 I am constructing a variable size table view within another view. The table view should not scroll so I am programmatically determining its content size and adjusting a height constraint so that the table view always fits its content. The problem I run into is a warning about a broken constraint: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which

Resize current view using NSLayoutConstraints

浪子不回头ぞ 提交于 2019-12-08 03:22:36
问题 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

iOS 12 Auto Layout界面自动布局系列3-使用原生NSLayoutConstraint添加布局约束

三世轮回 提交于 2019-12-08 02:12:05
本系列的第一篇文章介绍了自动布局的基本原理,第二篇文章通过一个简单的例子演示了如何使用Xcode的Interface Builder(简称IB)以可视化方式添加约束。本篇为该系列的第三篇文章,主要介绍如何通过写代码来添加布局约束。 说句题外话,不论是通过IB可视化加约束,还是写代码加约束,这两种方式各有优劣。写代码加约束是最基础最灵活的方式,但缺点是当界面较复杂时代码量会很繁冗易错。而通过IB可视化方式设置约束,操作简单直观,并支持在设计器中实时预览布局效果,但缺点是并非所有约束都能用IB来添加,而且不容易后期维护。所以掌握写代码添加自动布局约束是非常必要的。原本这篇文章是本系列的第二篇,但为了提高读者理解和接受的程度,最终还是把本编放在第三的位置。OK闲言少叙,我们进入正题。 NSLayoutConstraint类的定义 第一篇文章讲到, 每一个布局约束就是一个明确的线性变化规则 ,在数学上是以一次函数的形式表示,即: y = m * x + c   (公式3.1) 例如,对于下图计算器App,若想表达按钮5的顶部与按钮8的底部对齐,根据公式3.1,建立以下线性关系即可: 按钮5.顶部 = 1.0 * 按钮8.底部 + 0.0 这就是一个布局约束。 在UIKit中,每一个布局约束是一个NSLayoutConstraint实例。NSLayoutConstraint类的定义如下:

Add Views to UIScrollView Programmatically

柔情痞子 提交于 2019-12-08 00:41:09
问题 I have added the following code to my UIViewController: override func viewDidLoad() { super.viewDidLoad() viewBrochures.isUserInteractionEnabled = true let brochure1: UIImageView = UIImageView(image: UIImage(named: "image1")!) brochure1.translatesAutoresizingMaskIntoConstraints = false brochure1.contentMode = .scaleAspectFit brochure1.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 400) viewBrochures.addSubview(brochure1) let brochure2: UIImageView = UIImageView(image: