nslayoutconstraint

Swift 3 Create UILabel programmatically and add NSLayoutConstraints

拟墨画扇 提交于 2019-11-30 09:08:42
Hello I am trying to create a label programmatically and add NSLayoutConstraints so that it is centered in the superview regardless of screen size and orientation etc. I have looked but just can't find an example to follow. Here is what I have: let codedLabel:UILabel = UILabel() codedLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200) codedLabel.textAlignment = .center codedLabel.text = alertText codedLabel.numberOfLines=1 codedLabel.textColor=UIColor.red codedLabel.font=UIFont.systemFont(ofSize: 22) codedLabel.backgroundColor=UIColor.lightGray let heightConstraint:NSLayoutConstraint

UIStoryboard how to replace constraints programmatically?

我只是一个虾纸丫 提交于 2019-11-30 05:39:41
问题 I have a view controller laid out in a storyboard with autolayout enabled and am looking for a way to change constraints to allow for my view to rotate into landscape and rearrange buttons on the screen. When I try the code below, I get about two dozen "unable to satisfy constraints, breaking constraint..." messages that I cannot really decode. Is there a way to dynamically replace constraints from a storyboard with constraints that I specify programmatically? I want to completely override

How to set subviews with AutoLayout in UIScrollView programmatically?

我是研究僧i 提交于 2019-11-30 05:07:11
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; frame.origin.y = 0; frame.size = scrollView.frame.size; UIView *subview = [UIView new]; subview

How to change bottom layout constraint in iOS, Swift

寵の児 提交于 2019-11-30 04:53:09
I have scroll view as @IBOutlet @IBOutlet weak var mainScrollView: UIScrollView! I want to change the "Bottom space to: Bottom Layout Guide" constraint programmatically. First Item : Bottom Layout Guide.Top Relation : Equal Second Item: Scroll View.Bottom Constant: 0 -> 50 // (I want to change this programmatically) Priority: 1000 Multiplier: 1 How can I do this? Take the constraint as IBOutlet of NSLayoutConstraint . Set the constraint outlets and change constant value by : self.sampleConstraint.constant = 20 self.view.layoutIfNeeded() If you are adding constraint programatically like this:

UIView with dynamic height multiple UILabel

喜你入骨 提交于 2019-11-30 04:13:38
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. Badal Shah I made a demo for you according to your requirement. Download it from below link, Autoresize UIView and UILabel Step by Step Guide :- Step 1 :- Set

Set AutoLayout Size Class Programmatically?

萝らか妹 提交于 2019-11-30 03:38:53
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. iOS 8 introduces the active property on NSLayoutConstraint . It allows you to activate or deactivate a constraint. There are

Creating Auto Layout constraints to topLayoutGuide and bottomLayoutGuide in code

折月煮酒 提交于 2019-11-30 02:35:21
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 would automatically cause the constrained view to adjust position.) For a UIButton that you want to

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

寵の児 提交于 2019-11-30 02:25:33
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 right next to each other. I could manually calculate the frame of each button in my code, but should I

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

妖精的绣舞 提交于 2019-11-30 01:49:25
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 | |____________________________| | | | | | |_______________________________________| | | | | | 4 | |_______|___________________________

How to set UILabel only width and height and constraints programmatically

百般思念 提交于 2019-11-29 23:03:06
I want to create a UILabel programmatically with height, width and then I want to add constraints to it also programmatically for positioning the UILabel. Update: I want to create UI like this: How to create this UI All programatically Code to create one label label1 similarly I created two more label label2 and label3 UILabel *label1 = [[UILabel alloc]init]; label1.font = TitleFont; label1.numberOfLines=0; label1.text= @"Descriptions"; label1.lineBreakMode=NSLineBreakByWordWrapping; [label1 sizeToFit]; label1.backgroundColor=[UIColor blueColor]; label1.textColor=[UIColor blackColor]; label1