//
// ViewController.m
// UI-视图练习
//
// Created by jzq_mac on 15/7/23.
// Copyright (c) 2015年 jzq_mac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UIButton *button;
UILabel *label;
UITextField *textFiled;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(moveAction) userInfo:nil repeats:YES];
// UIButton 练习
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(150, 567, 100, 100);
[self.view addSubview:button];
button.layer.cornerRadius = 50;
button.backgroundColor = [UIColor blueColor];
// [button setTitle:@"点我啊" forState:UIControlStateNormal];
[button setTitle:@"点我干嘛" forState:UIControlStateSelected];
button.showsTouchWhenHighlighted = YES;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:20];
button.clipsToBounds = YES;
button.contentMode = YES;
button.alpha = 0.8;
[button setTitleShadowColor:[UIColor yellowColor] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"苹果"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
// UIlabel 练习
label = [[UILabel alloc]initWithFrame:CGRectMake(170, 70, 50, 500)];
[self.view addSubview:label];
label.backgroundColor = [UIColor redColor];
label.text = @"梦想还是要有的 万一实现了呢";
label.layer.cornerRadius = 50;
label.layer.masksToBounds = YES;
label.textColor = [UIColor yellowColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:30];
label.numberOfLines = 50;
for (int i = 0; i < 2; i ++) {
UIImageView *imgeView = [[UIImageView alloc]initWithFrame:CGRectMake(20 + (240 + 20)*i, 587, 80, 80)];
[self.view addSubview:imgeView];
imgeView.backgroundColor = [UIColor redColor];
imgeView.layer.cornerRadius = 40;
imgeView.layer.masksToBounds = YES;
imgeView.image = [UIImage imageNamed:@"苹果1"];
imgeView.tag = i + 100;
}
textFiled = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 375, 50)];
textFiled.delegate = self;
[self.view addSubview:textFiled];
textFiled.backgroundColor = [UIColor grayColor];
textFiled.placeholder = @"欢迎来到星际穿越";
textFiled.textAlignment = NSTextAlignmentCenter;
textFiled.font = [UIFont systemFontOfSize:30];
textFiled.returnKeyType = UIReturnKeyDefault;
UIImageView *left = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
left.image = [UIImage imageNamed:@"拳头"];
textFiled.leftView = left;
textFiled.leftViewMode = UITextFieldViewModeAlways;
textFiled.alpha = 0.5;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textFiled resignFirstResponder];
return YES;
}
- (void)moveAction
{
// 图片移动练习
[UIView animateWithDuration:2 animations:^{button.frame = CGRectMake(150, 0, 100, 100);} completion:^(BOOL finished){[UIView animateWithDuration:2 animations:^{button.frame = CGRectMake(150, 567, 100, 100);}];}];
for (int i =0; i<2; i++) {
UIImageView *imgeView = (UIImageView *)[self.view viewWithTag:i+100];
if (imgeView.tag == 100) {
imgeView.alpha = 1;
[UIView animateWithDuration:2 animations:^{
imgeView.alpha = 0.0;
}];
[UIView animateWithDuration:2 animations:^{
imgeView.frame = CGRectMake(160, 10, 80, 80);
} completion:^(BOOL finished) {
[UIView animateWithDuration:2 animations:^{
imgeView.frame = CGRectMake(20, 587, 80, 80);
}];
}];
}else{
imgeView.alpha = 1;
[UIView animateWithDuration:2 animations:^{
imgeView.alpha = 0.0;
}];
[UIView animateWithDuration:2 animations:^{
imgeView.frame = CGRectMake(160, 10, 80, 80);
} completion:^(BOOL finished) {
[UIView animateWithDuration:2 animations:^{
imgeView.frame = CGRectMake(270, 587, 80, 80);
}];
}];
}
}
label.alpha = 1;
[UIView animateWithDuration:4 animations:^{
label.alpha = 0.0;
}];
label.text = @"梦想还是要有的 万一实现了呢";
[UIView animateWithDuration:3 animations:^{
label.text = @"梦想还是要有的 万一实现了呢";
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 animations:^{
label.text = @"我就是我颜色不一样的花火";
}];
}];
}
- (void)click:(UIButton *)sender
{
if (sender.selected != YES) {
[button setBackgroundImage:[UIImage imageNamed:@"星际"] forState:UIControlStateNormal];
[button setTitle:@"点我啊" forState:UIControlStateNormal];
sender.selected = YES;
}else{
[button setBackgroundImage:[UIImage imageNamed:@"拳头"] forState:UIControlStateNormal ];
[button setTitle:@"点我干嘛" forState:UIControlStateSelected];
sender.selected = NO;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end