码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-动态创建按钮

时间:2015-07-29 15:37:47      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

//
//  ViewController.m
//  动态创建按钮
//
//  Created by YaguangZhu on 15/7/29.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //UIButton *button = [[UIButton alloc] init];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"hdhdh" forState:UIControlStateNormal];
    [button setTitle:@"sss" forState:UIControlStateHighlighted];
    
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    
    UIImage *imgNormal = [UIImage imageNamed:@"01"];
    UIImage *imgHigh = [UIImage imageNamed:@"02"];
    
    [button setBackgroundImage:(imgNormal ) forState:UIControlStateNormal];
    [button setBackgroundImage:(imgHigh) forState:UIControlStateHighlighted];
    
    button.frame = CGRectMake(50, 100, 100, 100);
    //单击事件
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)buttonClick
{
    NSLog(@"ssss");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

iOS-动态创建按钮

标签:

原文地址:http://www.cnblogs.com/zhuyaguang/p/4685769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!