IOS masonry dynamic Constrained control location

Source: Internet
Author: User


#import "FourViewController.h"
#import "View+masadditions.h"
#import "FiveViewControllerr.h"
#define WS (weakself) __weak __typeof (&*self) weakself = self;
#define Screen_width [UIScreen mainscreen].bounds.size.width
Static nsstring Const*[email protected] "Fourviewcontroller";
Static nsstring Const*[email protected] "Fourviewcontroller";

@interface Fourviewcontroller ()
@property (Strong, nonatomic) UIButton *move;
@property (Strong, nonatomic) UIButton *back;
@property (Strong, nonatomic) Uiimageview *imageview;
@property (assign, nonatomic) int s;
@end

@implementation Fourviewcontroller
+ (Instancetype) Createviewcontrollerwithstoryboard: (ID) createargs{
Uistoryboard *storyboard=[uistoryboard storyboardwithname: (NSString *) Kstoryboardname Bundle:nil];
Fourviewcontroller *vc=[storyboard instantiateviewcontrollerwithidentifier: (NSString *) kIdentifier];
return VC;
}
-(void) Viewdidload {
[Super Viewdidload];
[Self initrightitem];
_s=10;
[Self initfirstcontraints];
}
-(void) initfirstcontraints{
WS (WS);
UIView *view=[uiview New];
View.backgroundcolor=[uicolor Browncolor];
[Self.view Addsubview:view];
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (0);
Make.size.mas_equalTo (Cgsizemake ([UIScreen mainscreen].bounds.size.width,[uiscreen Mainscreen]. Bounds.size.height));
//    }];
int width= ([UIScreen mainscreen].bounds.size.width-_s*2-10)/2;

_move=[[uibutton Alloc]init];
_move.backgroundcolor=[uicolor Bluecolor];
[Self.view Addsubview:_move];
[_move mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (100);
Make.width.equalTo (@150);
Make.height.equalTo (@40);
}];
[_move addtarget:self Action: @selector (Moveframe) forcontrolevents:uicontroleventtouchupinside];
[_move settitle:@ "mobile picture" forstate:uicontrolstatenormal];

_back=[[uibutton Alloc]init];
_back.backgroundcolor=[uicolor Greencolor];
[Self.view Addsubview:_back];
[_back mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.right.equalTo (Self.view). With.offset (-_s);
Make.top.equalTo (Self.view). With.offset (100);
Make.width.equalTo (@150);
Make.height.equalTo (@40);
}];
[_back addtarget:self Action: @selector (Backframe) forcontrolevents:uicontroleventtouchupinside];
[_back settitle:@ "picture back" forstate:uicontrolstatenormal];

_imageview=[[uiimageview Alloc]init];
_imageview.image=[uiimage imagenamed:@ "Move"];
[Self.view Addsubview:_imageview];
[_imageview mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) moveframe{
_s=_s+5;;
NSLog (@ "_s:%d", _s);
[_imageview mas_updateconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200+_s);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) backframe{
_s=_s-5;;
NSLog (@ "_s:%d", _s);
[_imageview mas_updateconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200-_s);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) initrightitem{
[Self settitle:@ "dynamically change control position"];
Uibarbuttonitem *right=[[uibarbuttonitem alloc]initwithtitle:@ "multi-constraint" Style:uibarbuttonitemstyleplain target:self Action: @selector (right)];
Self.navigationitem.rightbarbuttonitem=right;
}
-(void) right{
Fiveviewcontrollerr *vc=[fiveviewcontrollerr Createviewcontrollerwithstoryboard:nil];
[Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS masonry dynamic Constrained control location

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.