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];

  • 相关阅读:
    Objective-C NSString基本使用 类方法 self关键字
    Objective-C 封装 继承 多态
    Objective-C 类和对象
    Objective-C 第一个小程序
    python基础--函数作用域
    python基础--函数1
    python基础--文件操作
    python基础--集合
    python基础--字典
    python基础--列表,元组
  • 原文地址:https://www.cnblogs.com/top5/p/2506610.html
Copyright © 2011-2022 走看看