RPAnchor
-
iOS 9.0+
-
Xcode 10.0+
-
pod V1.7.0+
-
MIT 许可证
需求
RPAnchor 是一个链式编程库,封装了系统的 NSLayoutConstraint。使用 RPAnchor 可以进行清洁编码。
将 RPAnchor 添加到项目中
CocoaPods 是将 RPAnchor 添加到项目的推荐方式。
1、在项目 Podfile 中为 RPAnchor 添加一个 pod 条目
pod 'RPAnchor'
或者
pod 'RPAnchor', :git => 'https://github.com/dengfeng520/RPLayoutAnchor'
2、通过运行以下命令安装 pod
pod install
3、使用以下方式在需要的地方包含 RPAnchor
#import "UIView+Anchor.h"
用法
//---------------------
UIImageView *fristGrilImg = [[UIImageView alloc] init];
fristGrilImg.rp_addView(self.view)
.rp_safeAreaTop(20,self.view,rpSafeTop)
.rp_centerX(0,self.view,rpCenterX)
.rp_height(250)
.rp_multiplierWidth(1.45,fristGrilImg,rpHeight);
fristGrilImg.image = [UIImage imageNamed:@"one_gril"];
fristGrilImg.backgroundColor = UIColor.redColor;
//---------------------
UIImageView *secondGrilImg = [[UIImageView alloc] init];
[self.view addSubview:secondGrilImg];
secondGrilImg.rp_config()
.rp_top(10,fristGrilImg,rpBottom)
.rp_centerX(0,self.view,rpCenterX)
.rp_width(280)
.rp_multiplierHeight(1.46,secondGrilImg,rpWidth);
secondGrilImg.image = [UIImage imageNamed:@"second_gril"];
//--------------------- redView
UIView *redView = [[UIView alloc] init];
redView
.rp_addView(self.view)
.rp_safeAreaTop(0,self.view,rpSafeTop)
.rp_left(0,self.view,rpLeft)
.rp_right(0,self.view,rpRight)
.rp_safeAreaBottom(0,self.view,rpSafeBottom);
redView.backgroundColor = UIColor.redColor;
//--------------------- blueView
UIView *blueView = [[UIView alloc] init];
blueView
.rp_addView(redView)
.rp_top(70,redView,rpTop)
.rp_left(90,redView,rpLeft)
.rp_greaterWidth(80)
.rp_greaterHeight(80);
blueView.backgroundColor = UIColor.blueColor;
//--------------------- greenBtn
UIButton *greenBtn = [[UIButton alloc] init];
greenBtn
.rp_addView(redView)
.rp_centerX(0,redView,rpCenterX)
.rp_centerY(0,redView,rpCenterY)
.rp_size(180,45);
greenBtn.backgroundColor = UIColor.greenColor;
//--------------------- orangeView
UIView *orangeView = [[UIView alloc] init];
orangeView
.rp_addView(redView)
.rp_centerX(0,redView,rpCenterX)
.rp_multiplierWidth(0.7,redView,rpWidth)
.rp_top(20,blueView,rpBottom)
.rp_height(45);
orangeView.backgroundColor = UIColor.orangeColor;