美文网首页
UI总结-UIImageView

UI总结-UIImageView

作者: Dear丶Musk | 来源:发表于2016-05-03 11:29 被阅读92次

                      UI总结-UIImageView

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

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

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

[_window release];

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

self.window.rootViewController = vc;

[vc release];

//UIImageView是用来显示图片的控件,它的父类是UIView

UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 300, 300)];

imgView.backgroundColor = [UIColor redColor];

[self.window addSubview:imgView];

[imgView release];

//添加图片

imgView.image = [UIImage imageNamed:@"stomach_00.jpg"];

//让他显示成一个圆形试图

imgView.layer.cornerRadius = 150;

imgView.layer.masksToBounds = YES;

//用UIimageView来播放一组图片可以形成动画的效果

UIImageView *tomCatImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 410, 300, 300)];

tomCatImage.backgroundColor = [UIColor blueColor];

//tomCatImage.tag = 101;

[self.window addSubview:tomCatImage];

[tomCatImage release];

tomCatImage.image = [UIImage imageNamed:@"stomach_00.jpg"];

//开始动画的按钮

UIButton *goButton = [UIButton buttonWithType:UIButtonTypeCustom];

goButton.frame = CGRectMake(100, 20, 50, 30);

goButton.backgroundColor = [UIColor grayColor];

[self.window addSubview:goButton];

[goButton setTitle:@"开始" forState:UIControlStateNormal];

[goButton addTarget:self action:@selector(goPlay:) forControlEvents:UIControlEventTouchUpInside];

//停止动画按钮

UIButton *endButton =[UIButton buttonWithType:UIButtonTypeCustom];

endButton.frame = CGRectMake(250, 20, 50, 30);

endButton.backgroundColor = [UIColor grayColor];

[self.window addSubview:endButton];

[endButton setTitle:@"停止" forState:UIControlStateNormal];

[endButton addTarget:self action:@selector(endPlay:) forControlEvents:UIControlEventTouchUpInside];

return YES;

}

-(void)goPlay:(UIButton *)button{

UIImageView *tomImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 410, 300, 300)];

tomImage.backgroundColor = [UIColor blueColor];

[self.window addSubview:tomImage];

[tomImage release];

//建一个数组,来存图片

NSMutableArray *imgArray = [ NSMutableArray array];

for (NSInteger i = 0; i < 33; i++) {

NSString *picName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];

UIImage *img = [UIImage imageNamed:picName];

[imgArray addObject:img];

}

//动画图片的数组

tomImage.animationImages = imgArray;

//动画的播放一遍的时长

tomImage.animationDuration = 2;

//动画重复播放的次数

tomImage.animationRepeatCount = 100;

//动画开始播放

[tomImage startAnimating];

}

-(void)endPlay:(UIButton *)button{

UIImageView *tomImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 410, 300, 300)];

tomImage.backgroundColor = [UIColor blueColor];

[self.window addSubview:tomImage];

[tomImage release];

tomImage.image = [UIImage imageNamed:@"stomach_00.jpg"];

}

相关文章

网友评论

      本文标题:UI总结-UIImageView

      本文链接:https://www.haomeiwen.com/subject/jjiklttx.html