Swift開発:AutoResizing自動レイアウトを実現
1513 ワード
/*
autoresizing :
view , , 20
, view ,
autoresizing
*/
let redView = UIView()
let wh:CGFloat = 100
let x:CGFloat = self.view.frame.size.width - wh - 20.0
let y:CGFloat = self.view.frame.size.height - wh - 20.0
redView.frame = CGRectMake(x,y,wh,wh)
redView.backgroundColor = UIColor.redColor()
var arm1 = UIViewAutoresizing.None
arm1.unionInPlace(UIViewAutoresizing.FlexibleRightMargin)
arm1.unionInPlace(UIViewAutoresizing.FlexibleLeftMargin)
arm1.unionInPlace(UIViewAutoresizing.FlexibleBottomMargin)
arm1.unionInPlace(UIViewAutoresizing.FlexibleTopMargin)
redView.autoresizingMask = arm1
print(redView.autoresizingMask)
self.view.addSubview(redView)
oc書き方
UIView * redView = [[ UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
CGFloat wh = 100;
CGFloat x = self.view.frame.size.width - wh;
CGFloat y = self.view.frame.size.height - wh;
redView.frame = CGRectMake(x, y, wh, wh);
redView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:redView];