双子座的ios1


//
//    ViewController.m
//    DynamicButton
//
//    Created  by  cyx  on  13-3-4.
//    Copyright  (c)  2013年  cyx.  All  rights  reserved.
//

#import  "ViewController.h"

@interface  ViewController  ()

@end

@implementation  ViewController

(void)viewDidLoad
{
        [super  viewDidLoad];
//  Do  any  additional  setup  after  loading  the  view,  typically  from  nib.
}

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

(IBAction)addButton:(id)sender  {
        CGRect  frame  CGRectMake(300,  300,  300,  50);//定义一个矩形区域,坐标为300,300,宽:300,高:50
       
        UIButton  *button  [UIButton  buttonWithType:UIButtonTypeRoundedRect];
        //创建一个圆角的矩形
        button.frame  frame;//给定button在view上的位置
       
        [button  setTitle:@"新添加一个按钮"  forState:UIControlStateNormal];
        //设置button标题,forState表示在何种情况下显现,常规状态显现
       
        button.backgroundColor  [UIColor  clearColor];
        //去除背景色
       
        button.tag  2000;
        //标记,如果想把一个窗口的所有button分成集中类型,那么不同button的tag属性分别设置成一个,就可以对tag不同的button分别操作了
       
        [button  addTarget:self  action:@selector(buttonClicked)  forControlEvents:(UIControlEventTouchUpIns ide)];
        //跟web的click事件一样,addaddTarget:self的意思是说,在这个方法在本类中也可以传入其他类的指针,当摁下的时候调用buttonClicked方法,UIControlEventTouchUpIns ide是指在按钮按下时响应
       
        [self.view  addSubview:button];
        //显示控件
}

(IBAction)buttonClicked:(id)sender
{
        UIAlertView  *alert  [[UIAlertView  alloc]  initWithTitle:@"提示"  message:@"单击了动态按钮"  delegate:self  cancelButtonTitle:@"sure"  otherButtonTitles:nil,  nil];
        [alert  show];
        [alert  release];
       
       
       
       
}



@end


原地址:http://my.oschina.net/plumsoft/blog?catalog=145903&p=1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值