代码添加按钮和按钮监听方法

来源:互联网 发布:淘宝api 生成淘口令 编辑:程序博客网 时间:2024/06/14 00:15
////  ViewController.m//  buttonTest////  Created by 殷东亮 on 14-8-31.//  Copyright (c) 2014年 easec. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)tapButton:(UIButton *)sender{    NSLog(@"我是%@",[sender.titleLabel text]);}- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    [button setFrame:CGRectMake(100, 100, 200, 200)];    [button setTitle:@"hello" forState:UIControlStateNormal];    [button setTitle:@"world" forState:UIControlStateHighlighted];    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];    [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];    [button addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];    [button setBounds:CGRectMake(200, 200, 200, 200)];    [button setBackgroundColor:[UIColor grayColor]];    UIImage *image = [UIImage imageNamed:@"photo/12.png"];    [button setBackgroundImage:image forState:UIControlStateNormal];    [self.view addSubview:button];    }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

0 0
原创粉丝点击