zoukankan      html  css  js  c++  java
  • iOS基础 UIButton UIImageView

    封装思想:将相同的重复东西保存到方法里,不同的东西用参数代替。不相同的东西交给方法调用者,相同东西自己搞定。

     

    一、UIButtonUIImageView的区别

    1.显示图片

    1> UIImageView只能显示一种图片(图片默认会填充整个UIImageView)  image\setImage:

    2> UIButton能显示2种图片

    背景 (背景会填充整个UIButton)  setBackroungImage:forState:

    前置(覆盖在背景上面的图片,按照之前的尺寸显示)  setImage:forState:

    还能显示文字

     

    2.点击事件

    1> UIImageView默认是不能响应点击事件

    2> UIButton能响应点击事件 : addTarget:action:forControlEvents:

     

    3.使用场合

    1> UIImageView : 只显示图片,不监听点击,点击了图片后不做任何反应

    2> UIButton : 既显示图片,又监听点击,点击了图片后做一些其他事情

     

    4.继承结构

    1> UIButton之所以能添加监听器来监听事件,是因为它继承自UIControl

    2> UIImagevIew之所以不能添加监听器来监听事件,是因为它直接继承自UIView

     

    二、UIImageView的帧动画

    @property(nonatomic,copy) NSArray *animationImages; // 设置需要播放的图片(到时会按照数组顺序播放)

    @property(nonatomic) NSTimeInterval animationDuration; // 动画的持续时间

    @property(nonatomic) NSInteger animationRepeatCount;  // 动画的执行次数(默认情况下是无限重复执行)

    - (void)startAnimating; // 开始动画

    - (void)stopAnimating;  // 停止动画

    - (BOOL)isAnimating; // 是否正在执行动画

     

    三、格式符补充

    %03d : 每个整数占据3个位置,多出的位置用0填充

    比如:

    * [NSString stringWithFormat:@"%03d", 0];  返回的是@"000"

    * [NSString stringWithFormat:@"%03d", 1];  返回的是@"001"

    * [NSString stringWithFormat:@"%03d", 12];  返回的是@"012"

    * [NSString stringWithFormat:@"%03d", 123];  返回的是@"123"

     

    四、加载图片的两种方式

    1.有缓存

    UIImage *image = [UIImage imageNamed:@"a.png"]

     

    2.无缓存

    // 全路径

    NSString *path = [[NSBundle mainBundle] pathForResource:@"a.png" ofType:nil];

    // patha.png的全路径

    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]

     

    五、UIToolbar的简单使用

    1.UIToolbar内部只能放UIBarButtonItem

     

    六、子控件的操作

    1.添加子控件 : addSubview:

    2.从父控件中移除 : removeFromSuperview

     

    七、动画

    1.头尾式

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0];

    // 需要执行动画的代码....

    [UIView commitAnimations];

     

    2.block

    [UIView animateWithDuration:1.0 animations:^{

        // 需要执行动画的代码....

    } completion:^(BOOL finished) { // 动画执行完毕后会自动调用这个block(这个代码段)

        

    }];

     

  • 相关阅读:
    习题2.4 递增的整数序列链表的插入(15 分)浙大版《数据结构(第2版)》题目集
    杭电 KazaQ's Socks
    B. Beautiful Paintings
    java之接口
    java之模板方法设计模式
    java之抽象类
    java之final关键字
    java之匿名内部类
    jvaa之初始化块
    java之单例设计模式
  • 原文地址:https://www.cnblogs.com/monicaios/p/3495824.html
Copyright © 2011-2022 走看看