Analysis of UIButton UIImage usage

Source: Internet
Author: User

Analysis of UIButton UIImage usage
123456789Ten One A - - the - - - + - + A at - - - - - in - to + - the * $Panax Notoginseng - the + A the + - $ $ - - the -Wuyi the 一、UIButton和UIImageView的区别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之所以能添加监听器来监听事件,是因为它继承自UIControl2> UIImagevIew之所以不能添加监听器来监听事件,是因为它直接继承自UIView 二、UIImageView的帧动画@property(nonatomic,copyNSArray *animationImages; // 设置需要播放的图片(到时会按照数组顺序播放)@property(nonatomicNSTimeInterval animationDuration; // 动画的持续时间@property(nonatomicNSInteger animationRepeatCount;  // 动画的执行次数(默认情况下是无限重复执行)- (void)startAnimating; // 开始动画- (void)stopAnimating;  // 停止动画- (BOOL)isAnimating; // 是否正在执行动画 三、格式符补充%03d : 每个整数占据3个位置,多出的位置用0填充比如:* [NSString stringWithFormat:@"%03d", 0];  返回的是@"000"* [NSString stringWithFormat:@"%03d", 7];  返回的是@"007"* [NSString stringWithFormat:@"%03d", 15];  返回的是@"015"* [NSString stringWithFormat:@"%03d", 134];  返回的是@"134" 四、加载图片的两种方式1.有缓存UIImage *image = [UIImage imageNamed:@"a.png"] 2.无缓存// 全路径NSString *path = [[NSBundle mainBundle] pathForResource:@"a.png" ofType:nil];// path是a.png的全路径UIImage *image = [[UIImage alloc] initWithContentsOfFile:path] 五、UIToolbar的简单使用1.UIToolbar内部只能放UIBarButtonItem 六、子控件的操作1.添加子控件 : addSubview:2.从父控件中移除 : removeFromSuperview

Analysis of UIButton UIImage usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.