您的位置:首页 > 产品设计 > UI/UE

IOS UILabel 、帧动画

2015-12-23 08:49 405 查看
   UILabel 、创建帧动画

    UILabel是一个标签控件适合放一些短的文本

     UILabel继承于UIView

     

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.rootViewController = [[ViewController alloc]init];

    [self.window makeKeyAndVisible];//让主窗口显示

    UILabel *label = [[UILabel alloc]init];// 把label对象实例化,任何对象都需要实例化

    label.frame = CGRectMake(150, 200, 200, 50);//给label设置frame

    label.backgroundColor = [UIColor greenColor];

    [self.window addSubview:label];//把创建的视图放到他的父视图上面
    label.text = @"世界你好!";//给label设置文本

    label.textColor = [UIColor orangeColor];//textColor设置字体颜色

    label.textAlignment = NSTextAlignmentCenter;//给UILabel设置对齐方式

    label.font = [UIFont systemFontOfSize:20];//设置文字大小,系统默认字体

   //UIFont、UIColor都是一种类用他们来创建的对象都需要实例化

    label.font = [UIFont boldSystemFontOfSize:20];//在加粗的同时设置字号大小

    //label.font = [UIFont systemFontOfSize:20 weight:4];//在加粗的同时设置字号大小

    label.font = [UIFont italicSystemFontOfSize:20];//设置字号大小

    label.shadowColor = [UIColor lightGrayColor];//shadowColor设置字体阴影并给字体阴影设置颜色

    

    label.shadowOffset = CGSizeMake(1, 1);//设置阴影偏移量

    label.numberOfLines = 1;//给内容设置行数0代表自适应行数,非0代表,是几就是几行

    label.adjustsFontSizeToFitWidth = YES;//给内容设置自适应行数

    

    UIImageView:用来显示图片

     创建帧动画四要素:

     1、设置间隔时间

     2、准备图片素材

     3、设置重复次数

     4、开始动画

   如果图片是PNG格式图片名不需要加后缀,否则都要加

    UIImageView *imageView = [[UIImageView alloc]init];

    imageView.image = [UIImage imageNamed:@"4.tiff"];

    imageView.frame = CGRectMake(10, 10, 300, 200);

    [self.window addSubview:imageView];

    imageView .animationDuration = 1;//animationDuration 设置动画的时间间隔

   //给帧动画准备素材

    imageView.animationImages = @[[UIImage imageNamed:@"4.tiff"],[UIImage imageNamed:@"5.tiff"],[UIImage imageNamed:@"6.tiff"],[UIImage imageNamed:@"7.tiff"],[UIImage imageNamed:@"8.tiff"],[UIImage imageNamed:@"9.tiff"]];//给帧动画准备素材

  如果动画图片较多的话可以使用for循环来写:

  NSMutableArray *images = [NSMutableArray array];

  for(int i = 0; i<图片数;i++){

  NSString *imageName = [NSString stringWithFormat:@"%d.tiff",i];

  UIImage *img = [UIImage imageNamed:imageName];

  [images addObjects:img];

  }

 imageView.animationImages = images;

    imageView.animationRepeatCount = 0;//给帧动画设置重复次数

    [imageView startAnimating];//开始动画

    延迟多少秒后执行相应的方法(start)

    [self performSelector:@selector(start) withObject:nil afterDelay:5];

- (void)start{

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios