// 按钮的实现
// ViewController.m
// 按钮练习
//
// Created by 李博 on 16/1/13.
// Copyright © 2016年 李博. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *lufei;
@property (weak, nonatomic) IBOutlet UITextField *txtnum1;
@property (weak, nonatomic) IBOutlet UITextField *txtnum2;
@property (weak, nonatomic) IBOutlet UILabel *result;
@end
@implementation ViewController
- (IBAction)up:(id)sender {
CGPoint frame =self.lufei.center;
frame.y+=5;
self.lufei.center=frame;
}
- (IBAction)bigger:(id)sender {
CGRect a=self.lufei.bounds;
a.size.height+=5;
a.size.width+=5;
self.lufei.bounds=a;
}
- (IBAction)jisuan:(id)sender {
//接收值
NSString *num1=self.txtnum1.text;
NSString *num2=self.txtnum2.text;
int a = [num1 intValue];
int b = [num2 intValue];
int m = a+b;
self.result.text=[NSString stringWithFormat:@"%d",m];
//回收键盘
//[self.view endEditing:YES];
[self.txtnum1 resignFirstResponder];
[self.txtnum2 resignFirstResponder];
}
//通过纯代码的方式创建一个按钮
//1.注意是在系统创建的控制器的view中添加****
- (void)viewDidLoad {
[super viewDidLoad];
//1.先建一个按钮对象
UIButton *button =[[UIButton alloc]init];
//2.设置按钮显示的文字
//默认状态下 deflout/normal
[button setTitle:@"路飞" forState:UIControlStateNormal];
//高亮状态下
[button setTitle:@"摩托" forState:UIControlStateHighlighted];
//3.设置按钮的背景图片
//根据图片名称,创建图片对象
UIImage *normal =[UIImage imageNamed:@"button_01"];
UIImage *heighlighted =[UIImage imageNamed:@"button_02"];
//默认状态下 背景图片是哪个
[button setBackgroundImage:normal forState:UIControlStateNormal];
//高亮状态下
[button setBackgroundImage:heighlighted forState:UIControlStateHighlighted];
//4.按钮位置的frame(位置,大小)
button.frame=CGRectMake(100, 100, 100, 100);
//5.设置按钮在不同状态下文字的yanse
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//6.添加到界面中
[self.view addSubview:button];
//按钮的事件 (单击事件)********注意方法的冒号
[button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//- (void) didClickButton{
// NSLog(@"你别按我!!");
// UIView *A =[self.view viewWithTag:1];
// [A removeFromSuperview];
//}
- (void) didClickButton:(UIButton *)sender{
NSLog(@"你别按我!!%@",sender.currentTitle);
}
@end
/
qq登陆界面
//
// ViewController.m
// QQ登陆界面
//
// Created by 李博 on 16/1/14.
// Copyright © 2016年 李博. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtQQNum;
@property (weak, nonatomic) IBOutlet UITextField *txtQQpassWord;
@end
@implementation ViewController
- (IBAction)didClickButton:(id)sender {
NSString *qq =self.txtQQNum.text;
NSString *password=self.txtQQpassWord.text;
NSLog(@"qq账号 %@,密码%@",qq,password);
[self.view endEditing:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end