ios - How to add constraints programatically to place a label at the left bottom of the screen? -
I want to put a label at the bottom left of the screen: I therefore added the following code:
< Code> UILabel * versionLabel = [UILabel new]; VersionLabel.text = @ "Some Text"; VersionLabel.textColor = [UIColor whiteColor]; VersionLabel.font = [UIFont systemFontOfSize: 10.0]; [Self.view addSubview: versionLabel]; [Version label set transclusions atomicisingmusk intensifications: no]; NSDictionary * View = NSDictionaryOfVariableBindings (versionLabel); [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "H:; -3-[versionLabel]" option: 0 metric: zero views: consideration]]; [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "V: [versionLabel] -3- |" Options: 0 metric: zero views: view]];
My problem is that the label always ends up on the top left when I add obstacles, then there is no way to move it down.
If you wrap UITableViewController in UIViewController, you can see the layout as the label and table view . ViewController {} - (zero) viewDidLoad {I input it manually, but you can interface Builder can use an outlet from UITableViewController * tableViewController = [YourCustomTableViewController new]; [Self addChildViewController: tableViewController]; UIView * tableView = tableViewController.view; UILabel * label1 = [UILabel new]; Label1.text = @ "Some Text"; Label1.font = [UIFont systemFontOfSize: 10.0]; Label1.translatesAutoresizingMaskIntoConstraints = No; TableviewTransletsAutorizingMuskInstension = No; [Self.view addSubview: tableView]; [Self.view addSubview: label1]; NSDictionary * Visual = NSDictionaryOfVariableBindings (tableView, label1); [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "H: | [Table View] |" | // tableview take full width option: 0 metric: zero view: view]]; [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "H:; -3- [Label 1]" // Label 3 pixels with the left option: 0 metric: zero view: view]]; [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "V: | [tableView] - [label 1] -3- |" // Attach a table view at the top, then space, then label, 3px, then the options below: 0 metric: zero view: view]]; } @end
Comments
Post a Comment