您的位置:首页 > 产品设计 > UI/UE

iOS学习应用开发就业课_004:UIButton时间处理

2016-05-31 11:03 519 查看
难点:

1.创建2个UIButton的时间

a按钮:移动View

b按钮:回复位置

2.保证View的移动

复习次数:5次

5月13日

5月16日

5月26日

5月30日

5月31日

源码:

- (void)viewDidLoad
{

[super
viewDidLoad];

UIButton *myBtn1=[UIButton
buttonWithType:UIButtonTypeRoundedRect];

myBtn1.frame=CGRectMake(50,
500, 80,
40);

[myBtn1
setTitle:@"按下移动"
forState:UIControlStateNormal];

[myBtn1
addTarget:self
action:@selector(pressMove)
forControlEvents:UIControlEventTouchUpInside];

[self.view
addSubview:myBtn1];

UIButton *myBtn2=[UIButton
buttonWithType:UIButtonTypeRoundedRect];

myBtn2.frame=CGRectMake(50,
150, 80,
40);

[myBtn2
setTitle:@"按下移动"
forState:UIControlStateNormal];

[myBtn2
addTarget:self
action:@selector(pressRect)
forControlEvents:UIControlEventTouchUpInside];

[self.view
addSubview:myBtn2];

UIView *vc=[[UIView
alloc] initWithFrame:CGRectMake(1,
250,
100, 100)];

vc.backgroundColor=[UIColor
yellowColor];

vc.tag=101;

[self.view
addSubview:vc];

}

-(void)pressMove

{

UIView *vc=[[UIView
alloc]init];

vc=[self.view
viewWithTag:101];

vc.backgroundColor=[UIColor
darkGrayColor];

vc.frame=CGRectMake(vc.frame.origin.x+10,
vc.frame.origin.y+50,
200,
200);

[self.view
addSubview:vc];

}

-(void)pressRect

{

UIView *vc=[[UIView
alloc]init];

vc=[self.view
viewWithTag:101];

vc.frame=CGRectMake(1,
250, 100,
100);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: