UIButton各种属性

来源:互联网 发布:淘宝店铺免费装修教程 编辑:程序博客网 时间:2024/06/06 01:52

 //创建圆角button

    UIButton *button =[UIButtonbuttonWithType:UIButtonTypeRoundedRect];     

 //指定button的位置和大小

    button.frame CGRectMake(10,10, 7575);

  //给button设置标签,用来辨别点击的是哪个button,常用在委托方法中。

    button.tag = 0;

 //定义按钮标题

     [button setTitle:@"ButtonTitle" forState:UIControlStateNormal];

  //定义按钮标题字体格式

     [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];

  //给button添加委托方法,即点击触发的事件。

    [button addTarget:selfaction:@selector(touchButton1:) forControlEvents :UIControlEventTouchUp Inside];

 //给button添加图片 

   [button setImage:[UIImageimageNamed:@"blue_bg(2).png"forState:UIControlStateNormal];

 //将button加入视图当中

    [view addSubview:button];



原创粉丝点击