iOS开发UI之UILabel的基本使用

继承关系

UIImageView --> UIView

一. 什么是UIImageView

lUIKit框架提供了非常多的UI控件,但并不是每一个都很常用,有些控件可能1年内都用不上,有些控件天天用,比如UIButton、UILabel、UIImageView、UITableView等等

lUIImageView极其常用,功能比较专一:显示图片


二. UIImageView的常见属性

1. 创建UIImageView

  1. UIImageView *image = [[UIImageView alloc] init];

2. 设置尺寸

  1. image.frame = CGRectMake(0, 0, goodsW, goodsW);

3. 设置图片

  1. image.image = [UIImage imageNamed:icon];

4. 加载动画图片

@property(nonatomic,copyNSArray *animationImages

5. 动画图片的持续时间

@property(nonatomicNSTimeInterval animationDuration

6. 动画的播放次数(默认是0,代表无限播放)

@property(nonatomicNSInteger      animationRepeatCount


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

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

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


三. UIImageView加载动画

1. 首尾方式

  1. // 1.定义一个动画
  2. [UIView beginAnimations:nil context:nil];
  3. // 2.设置动画持续时间
  4. [UIView setAnimationDuration:2.0];
  5. // 3.取出image的frame
  6. CGRect tmepF = self.image.frame;
  7. // 取出image的bounds
  8. CGRect tmepB = self.image.bounds;
  9. // 4.根据按钮的tag判断方向
  10. switch (btn.tag) {
  11. case 10: // 上
  12. tmepF.origin.y -= f;
  13. break;
  14. case 20: // 下
  15. tmepF.origin.y += f;
  16. break;

  1. }
  2. // 将tmep赋值给按钮
  3. self.image.frame = tmepF;
  4. self.image.bounds = tmepB;
  5. // 提交动画
  6. [UIView commitAnimations];
2. 将图片加载到animationImages
  1. // 6.将图片数组加入到动画中
  2. self.iconImage.animationImages = images;
  3. // 7.设置动画次数
  4. self.iconImage.animationRepeatCount = 1;
  5. // 8.设置动画持续时间
  6. self.iconImage.animationDuration = count * 0.08;
  7. // 9.开始动画
  8. [self.iconImage startAnimating];

3. block 动画

  1. // 慢慢出现(出现动画持续1秒)
  2. [UIView animateWithDuration:1.0 animations:^{
  3. self.hudLabel.alpha = 1.0;
  4. } completion:^(BOOL finished) {
  5. // 1.5秒后,再慢慢消失(消失动画持续1秒)
  6. [UIView animateWithDuration:1.0 delay:1.5 options:kNilOptions animations:^{
  7. self.hudLabel.alpha = 0.0;
  8. } completion:nil];
  9. }];





原文地址:https://www.cnblogs.com/Xfsrn/p/4842416.html