nslayoutconstraint

how can I use one storyboard for 4“ and 3.5” iphone screens with autolayout (ios6 + ios7)?

有些话、适合烂在心里 提交于 2019-11-29 21:07:41
While there are many questions and answers about building a storyboard layout that would work both on 4" and 3.5" screen sizes, I couldn't find a suitable solution for the following scenario. I use autolayout with ios6 (and ios7), and I don't have to support landscpae or ipad. I have a UIView with several subviews, which have to look as the mockup below. It is easy to set up autolayout constraints in the storyboard to fit either of the screen sizes. My question is - how do I make autolayout choose the correct constraints depending on the screen size at runtime? Note, that I DONT want to use 2

iOS 7: Misplaced View Frame for “Label - Label” will be different at run time

时光总嘲笑我的痴心妄想 提交于 2019-11-29 20:07:55
I just finished an app on iOS 6 and bought a developer account a week ago so haven't had much time playing with the iOS 7 SDK. Just downloaded the Golden Master version and trying to upgrade my app to be compatible with iOS 7. I received a lot of warnings saying Misplaced View Frame for "Label - Label" will be different at run time. and I am unable to run the program. The project contains tableview and its is parsing and displaying XML feed from an RSS. How to fix this issue? I had the same issue and I get below response form Apple: You need to update the constraints to match the frames of

Hiding a UIView using AutoLayout constraints

孤街浪徒 提交于 2019-11-29 19:45:16
From time to time I have a subview that I would like to remove from a layout. Not only should it be hidden, but it should not be considered part of the view's 'flow', so to speak. An example: I am looking for a strategy to hide the orange view programmatically. The layout of the boxes, and their content, is via autolayout. Two things to note: the orange box is defining its vertical height based on the content, plus some top/bottom offsets for margins. So, setting the labels' text to nil will only 'shrink' the view down to it's internal margins, it won't have a height of 0. Similarly, the

“Width equals height” constraint in Interface Builder

二次信任 提交于 2019-11-29 19:41:14
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. Jano 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 because the width/height editor lacks the fields to relate to another property or set the ratio:

What is the difference between all these Auto Layout update methods? Are all necessary?

拜拜、爱过 提交于 2019-11-29 18:53:13
In the code below, these four methods are called for layout reasoning. I'm a little confused why all of them are needed, though, and what they do differently from one another. They're used in the process to make a cell's height be dynamic with Auto Layout. (Taken from this repository from this question .) [cell setNeedsUpdateConstraints]; [cell updateConstraintsIfNeeded]; [cell.contentView setNeedsLayout]; [cell.contentView layoutIfNeeded]; And it's from this block of code for the cell's height: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

Get reference to NSLayoutConstraint using Identifier set in storyboard

早过忘川 提交于 2019-11-29 17:09:49
问题 I was setting the constraints of a button using a storyboard. I saw an option, "Identifier" in the constraint's properties. I want to make a reference to this constraint, to change its value in code, to move an object. How can I get a reference to this NSLayoutContraint from this Identifier. I read the documentation, it was written like this @interface NSLayoutConstraint (NSIdentifier) /* For ease in debugging, name a constraint by setting its identifier, which will be printed in the

How to set subviews with AutoLayout in UIScrollView programmatically?

送分小仙女□ 提交于 2019-11-29 02:56:38
问题 I am creating app with UiScrollview and UIPagectontrol using Autolayout Programmatically, for I have Created TKScroller as subclass of UIView, I am init it using Some Mode and Array. TKScroller.m -(void)setData{ [self layoutIfNeeded]; CGRect mainFrame=self.frame; [self layoutIfNeeded]; CGRect mainFrame=self.frame; UIView *lastview; NSMutableArray* manualConstraints = [NSMutableArray array]; for (int i=0; i<arrayData.count ; i++) { CGRect frame; frame.origin.x = scrollView.frame.size.width * i

UIView with dynamic height multiple UILabel

空扰寡人 提交于 2019-11-29 01:37:23
问题 I'm making a custom UIView with 2 UILabel in it, with each UILabel having dynamic height. I'm unable to set constraints for dynamic height. (I'm new to Auto-Layout & iOS stuff). Both UILabels are connected to each other from Top & Bottom, and are Horizontally aligned to superview. And when I change content of one of the UILabel, UIView and UILabel does not resize as required. Please suggest. Attaching screenshots for current constraints. 回答1: I made a demo for you according to your

Set AutoLayout Size Class Programmatically?

一曲冷凌霜 提交于 2019-11-29 00:42:02
问题 With iOS 8 and Xcode 6, in storyboards we now have the screen size grid letting us select a size class. Where you can select layout formatting for the different screen sizes. I have found this brilliantly helpful, as it allows me to set the base constraints and then unique ones for each screen size. My question is, can you do this programmatically? I create my NSLayoutConstraint as normal but I need to be able to specify different constraints for different screen sizes. 回答1: iOS 8 introduces

How to use AutoLayout to position UIButtons in horizontal lines (wrapping, left aligned)?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 22:47:14
问题 I need to create a couple of UIButtons with various widths programmatically in my app (iOS 6.0 and above). I want to display the buttons in a "wrap around" style: Starting from the left edge, each button should be positioned next to each other horizontally (in a defined order), and if a button does not fit in the current "line", it should start a new line on the left edge below the previous line. Note: I don't want a table/grid, since the buttons have different widths, and I want to have one