zoukankan      html  css  js  c++  java
  • UIButton的详细使用

    UIbutton作为简单且频繁被使用的控件,其地位在整个app开发中不可小视。在IB中使用button相对来说很简单,很容易上手,但在多视图开发中button通常会被即时生成,并设置其属性和功能,即通过代码生成。如下是我对button的理解。

      //创建圆角button

         UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];      

      //指定button的位置和大小

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

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

         button.tag = 0;

      //定义按钮标题

         [button setTitle:@"Button Title" forState:UIControlStateNormal];

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

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

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

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

      //给button添加图片 

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

      //将button加入视图当中

         [view addSubview:button];

     

    使用技巧:

    button不仅可以用来加载图片还可以加载label来实现特定文本的显示。

    [button addSubview:label];

  • 相关阅读:
    乐观锁和悲观锁
    c++ inline使函数实现可以在头文件中,避免多重定义错误
    无锁队列的实现
    同步异步阻塞非阻塞
    log(m+n)找第k大
    ios开发常见的 工具 - 值得收藏
    iOS 性能优化得 方法
    搭建 安卓开发环境 !
    项目支持 64 - bit
    AFN学习笔记
  • 原文地址:https://www.cnblogs.com/top5/p/2506610.html
Copyright © 2011-2022 走看看