读书人

给初学者写的tapGesture和返回按钮写法

发布时间: 2014-01-13 17:16:02 作者: rapoo

给菜鸟写的tapGesture和返回按钮写法的示例
菜鸟真的很菜,还不爱学习,不怕神一样的对手,只怕不爱学习的菜鸟。

- (void)viewDidLoad{    [super viewDidLoad];        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];    UIImage *returnBtnImage = [UIImage imageNamed:@"return_btn.png"];    [btn setFrame:CGRectMake(0, 0, returnBtnImage.size.width, returnBtnImage.size.height)];    [btn setBackgroundImage:returnBtnImage forState:UIControlStateNormal];    [btn setTitle:@"  返回" forState:UIControlStateNormal];    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];    [btn.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];    [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];        UIBarButtonItem *backBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];    self.navigationItem.leftBarButtonItem = backBtn;        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCheck:)];    tap.numberOfTapsRequired = 1;    [imageView addGestureRecognizer:tap];}

读书人网 >移动开发

热点推荐