圖片適配放闺、控件適配托呕,xib適配瘦麸。Masonry
//圖片適配
//3gs和4的屏幕縮放系數(shù)是1. 4s~6s屏幕縮放系數(shù)是2. 6+和6s+縮放系數(shù)是3.一張20x20的圖片,在3gs和4上正常顯示,在縮放系數(shù)是2或者3的設(shè)備上會被放大縮放(模糊),在2上兩倍,在3上三倍.所以我們現(xiàn)在一般只做兩倍和三倍圖.
//如果沒有三倍圖,會自動找到2倍圖放大
//example.png ??example@2x.png ?example@3x.png 加載圖片用:imageNamed:@"example.png"
//PDF不失真
//NSString *path = [[NSBundle mainBundle] pathForResource:@"0" ofType:@"png"];
//_imageView.image = [UIImage imageWithContentsOfFile:path];
_imageView.image= [UIImageimageNamed:@"臉"];
//字體有大有小字體顏色不會失真篱瞎,顏色是矢量數(shù)據(jù)
NSLog(@"%@",[UIFont familyNames]);
//設(shè)置字體類型和大小
//[UIFont fontWithName:<#(nonnull NSString *)#> size:<#(CGFloat)#>];
用于生成各種需要的Icon的軟件
//控件適配
//使用第三方庫Masonry進(jìn)行約束適配
UIView *titleView = [[UIView alloc] init];
titleView.backgroundColor= [UIColor redColor];
//對視圖進(jìn)行約束之前,要保證該視圖已經(jīng)添加到其父視圖上
[self.view addSubview:titleView];
//Masonry的使用
[titleView mas_makeConstraints:^(MASConstraintMaker*make) {
//頂部的偏移量為0
make.top.offset(0);
//左側(cè)的偏移量為0
make.left.offset(0);
//右側(cè)的偏移量為0
make.right.offset(0);
//定高度
make.height.offset(60);
}];
UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor= [UIColor orangeColor];
[self.view addSubview:bgView];
[bgView mas_makeConstraints:^(MASConstraintMaker*make) {
make.top.offset(20);
make.left.offset(20);
//右下位置為正
//左上位置為負(fù)
make.right.offset(-20);
make.bottom.offset(-20);
}];
UIView *view1 = [[UIView alloc] init];
view1.backgroundColor= [UIColor cyanColor];
[bgView addSubview:view1];
UIView *view2 = [[UIView alloc] init];
view2.backgroundColor= [UIColorcyanColor];
[bgView addSubview:view2];
//等距等寬等高
[view1 mas_makeConstraints:^(MASConstraintMaker*make) {
//等高
make.top.offset(20);
make.bottom.offset(-20);
//等距
make.left.offset(20);
make.right.equalTo(view2.mas_left).offset(-20);
//view1和view2等寬
make.width.equalTo(view2.mas_width);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker*make) {
//等高
make.top.offset(20);
make.bottom.offset(-20);
//等距
make.right.offset(-20);
}];
//適配的縮放匹配
UIView *view = [[UIView alloc] init];
view.backgroundColor= [UIColor greenColor];
[self.view addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker*make) {
make.top.offset(0);
make.left.offset(0);
// ???????make.width.offset(self.view.frame.size.width/2);
//multipliedBy縮放系數(shù)
make.width.equalTo(self.view.mas_width).multipliedBy(0.5);
make.height.equalTo(self.view.mas_height).multipliedBy(0.5);
}];
//XIB適配
//使用xib約束,上,下,左,右,長度,高度,只需要四個即可約束
//不需要外邊框Constrain to margins
//對于提示錯誤或者警告,可以對其進(jìn)行點(diǎn)擊修正,之后要update
//等寬,等高都可以使用
//點(diǎn)擊約束線條可以設(shè)置比例
//對于要設(shè)置子視圖的關(guān)系比例,可以選中子視圖及其需要成為父視圖的選項(xiàng),進(jìn)行約束