1 Star 0 Fork 0

AppleDream / iOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ViewController.m 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
AppleDream 提交于 2016-05-19 23:49 . 苹果自带自动布局
//
// ViewController.m
// Layout代码
//
// Created by hyl on 16/5/16.
// Copyright © 2016年 hyl. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)viewDidLoad{
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints=NO;
UIView *viewRed=[[UIView alloc]init];
viewRed.backgroundColor=[UIColor redColor];
viewRed.translatesAutoresizingMaskIntoConstraints=NO;
[self.view addSubview:viewRed];
//viewRed.frame=CGRectMake(100, 100, 100, 50);
NSLayoutConstraint *widthConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:100];
[viewRed addConstraint:widthConstraint];
NSLayoutConstraint *heightConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:50];
[viewRed addConstraint:heightConstraint];
NSLayoutConstraint *leftContraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:30];
[self.view addConstraint:leftContraint];
NSLayoutConstraint *topConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:30];
[self.view addConstraint:topConstraint];
}
@end
Objective-C
1
https://gitee.com/HYLAppleDream/iOS.git
git@gitee.com:HYLAppleDream/iOS.git
HYLAppleDream
iOS
iOS
master

搜索帮助