您的位置:首页 > 其它

控件继承、动画

2015-12-11 16:46 225 查看
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

ViewController * vc =[[ViewController alloc]init];

self.window.rootViewController = vc;

self.window.backgroundColor = [UIColor grayColor];

// makeKeyAndVisible:让窗口是主窗口,并且显示在屏幕上

[self.window makeKeyAndVisible];

/*

* 控件之间的继承关系

* NILable

* UIImageView

*/

// UIView 显示一块有颜色的视图

UIView *view = [[UIView alloc]init];

view.frame = CGRectMake(100, 100, 300, 300);

[self.window addSubview:view];

view.backgroundColor = [UIColor orangeColor];

//UILable 标签控件,适合放一些短的文本。

//UILable继承于UIView

//把lable对象实例化,任何对象都要实例化

UILabel * lable = [[UILabel alloc]init];

// 给lable设置frame

lable.frame = CGRectMake(200, 200, 200, 200);

// 给UILable设置文本

lable.text = @"zkysdfdsghhhjjghjkgiu";

lable.textColor = [UIColor whiteColor];

// 给UILable设置对齐方式:

lable.textAlignment =NSTextAlignmentNatural;

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

// 字体大小

lable.font = [UIFont systemFontOfSize:25];

// 加粗字体的同时还设置了字体的大小

lable.font = [UIFont boldSystemFontOfSize:26];

// 设置斜体的同时还设置了字体大小

lable.font = [UIFont italicSystemFontOfSize:28];

// 设置阴影并给设置阴影颜色

lable.shadowColor = [UIColor blueColor];

// 设置阴影偏移量

// lable.shadowOffset = CGSizeMake(6, 6);

// 给内容设置行数,0代表自适应行数,非0,是几就是几行

lable.numberOfLines = 0;

// 自适应字体,让内容尽量一行显示

lable.adjustsFontSizeToFitWidth = YES;

lable.backgroundColor = [UIColor redColor];

[self.window addSubview:lable];

// 设置imgView 显示图片

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

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

// imgView.image = [UIImage imageNamed:@"boy1.tiff"];

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

[self.window addSubview:imgView];

/*

* 创建帧动画三要素

* 1、设置间隔时间

* 2、准备图片素材

* 3、设置重复次数

* 4、开始动画

*/

// animationDuration 设置动画的时间间隔

imgView.animationDuration = 1;

// 将实例化的对象放入数组中

UIImage * img1=[UIImage imageNamed:@"boy1.tiff"];

UIImage * img2=[UIImage imageNamed:@"boy2.tiff"];

UIImage * img3=[UIImage imageNamed:@"boy3.tiff"];

UIImage * img4=[UIImage imageNamed:@"boy4.tiff"];

UIImage * img5=[UIImage imageNamed:@"boy5.tiff"];

UIImage * img6=[UIImage imageNamed:@"boy6.tiff"];

UIImage * img7=[UIImage imageNamed:@"boy7.tiff"];

UIImage * img8=[UIImage imageNamed:@"boy8.tiff"];

NSArray * array = @[img1,img2,img3,img4,img5,img6,img7,img8];

// animationImages 给帧动画准备素材

imgView.animationImages =array;

// RepeatCount 设置重复次数

imgView.animationRepeatCount = 50;

// 开始动画

[imgView startAnimating];

// 结束动画

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