UI之responder
2015-12-14 10:03
429 查看
按钮响应事件
#import "MangoView.h"
//引入头文件
#import "mainViewController.h"
@implementation MangoView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self costom];
}
return self;
}
- (void)costom{
UIView *aView = [[UIView alloc]initWithFrame:self.frame];
aView.backgroundColor = [UIColor greenColor];
[self addSubview:aView];
[aView release];
UIView *bView = [[UIView alloc]initWithFrame:CGRectMake(30, 40, 330, 250)];
bView.backgroundColor = [UIColor redColor];
[self addSubview:bView];
[bView release];
UIView *eView = [[UIView alloc]initWithFrame:CGRectMake(30, 330, 330, 300)];
eView.backgroundColor = [UIColor yellowColor];
[self addSubview:eView];
[eView release];
UIView *cView = [[UIView alloc]initWithFrame:CGRectMake(40, 40, 250, 100)];
cView.backgroundColor = [UIColor lightGrayColor];
[eView addSubview:cView];
[cView release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(80, 30, 80, 40);
button.backgroundColor = [UIColor blackColor];
[button setTitle:@"button" forState:UIControlStateNormal];
[button setTitle:@"" forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(bun) forControlEvents:UIControlEventTouchUpInside];
[cView addSubview:button];
UIView *dView = [[UIView alloc]initWithFrame:CGRectMake(40, 160, 250, 100)];
dView.backgroundColor = [UIColor lightGrayColor];
// userInteractionEnabled用户交互是否可用,YES可,NO不可
// dView.userInteractionEnabled = NO;
[eView addSubview:dView];
[dView release];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(80, 40, 80, 40);
[btn setTitle:@"Touch" forState:UIControlStateNormal];
[btn setTitle:@"" forState:UIControlStateHighlighted];
btn.backgroundColor = [UIColor brownColor];
[btn addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];
[dView addSubview:btn];
}
- (void)touch{
NSLog(@"touch");
}
- (void)bun{
NSLog(@"button");
}
#import "mainViewController.h"
//引入头文件
#import "MangoView.h"
@interface mainViewController ()
@end
@implementation mainViewController
- (void)loadView{
[super loadView];
self.view = [[MangoView alloc]initWithFrame:self.view.frame];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "MangoView.h"
//引入头文件
#import "mainViewController.h"
@implementation MangoView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self costom];
}
return self;
}
- (void)costom{
UIView *aView = [[UIView alloc]initWithFrame:self.frame];
aView.backgroundColor = [UIColor greenColor];
[self addSubview:aView];
[aView release];
UIView *bView = [[UIView alloc]initWithFrame:CGRectMake(30, 40, 330, 250)];
bView.backgroundColor = [UIColor redColor];
[self addSubview:bView];
[bView release];
UIView *eView = [[UIView alloc]initWithFrame:CGRectMake(30, 330, 330, 300)];
eView.backgroundColor = [UIColor yellowColor];
[self addSubview:eView];
[eView release];
UIView *cView = [[UIView alloc]initWithFrame:CGRectMake(40, 40, 250, 100)];
cView.backgroundColor = [UIColor lightGrayColor];
[eView addSubview:cView];
[cView release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(80, 30, 80, 40);
button.backgroundColor = [UIColor blackColor];
[button setTitle:@"button" forState:UIControlStateNormal];
[button setTitle:@"" forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(bun) forControlEvents:UIControlEventTouchUpInside];
[cView addSubview:button];
UIView *dView = [[UIView alloc]initWithFrame:CGRectMake(40, 160, 250, 100)];
dView.backgroundColor = [UIColor lightGrayColor];
// userInteractionEnabled用户交互是否可用,YES可,NO不可
// dView.userInteractionEnabled = NO;
[eView addSubview:dView];
[dView release];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(80, 40, 80, 40);
[btn setTitle:@"Touch" forState:UIControlStateNormal];
[btn setTitle:@"" forState:UIControlStateHighlighted];
btn.backgroundColor = [UIColor brownColor];
[btn addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];
[dView addSubview:btn];
}
- (void)touch{
NSLog(@"touch");
}
- (void)bun{
NSLog(@"button");
}
#import "mainViewController.h"
//引入头文件
#import "MangoView.h"
@interface mainViewController ()
@end
@implementation mainViewController
- (void)loadView{
[super loadView];
self.view = [[MangoView alloc]initWithFrame:self.view.frame];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- 通过velocity模板和Hibernate sql-query的实现动态hql
- 【LEETCODE】232-Implement Queue using Stacks
- [mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
- UI之touchEvent
- UIViewController的生命周期
- UIImageView添加点击事件
- 使用go build 进行条件编译
- iOS开发中UITableview控件的基本使用及性能优化方法
- 《NSUserDefaults数据存储和 UIScrollView 的解说,和引导也的创建》
- Arduino - 利用红外避障(障碍检测)进行计数
- 网页性能管理详解:浅谈chrome-Timeline及window.requestAnimationFrame()方法
- 关于android官方提供的BluetoothChat源码连接不上蓝牙适配器的问题
- DVWA系列之12 利用Burpsuite进行暴力破解
- DVWA系列之12 利用Burpsuite进行暴力破解
- URAL 1183 Brackets Sequence DP 路径输出
- iOS之UI--转场动画
- Java Map排序——按key和按value
- UICollectionView点击 UICollectionView_基础 九宫格
- Adobe Flash Builder 4.7破解方法
- flexmojos build languageBundle