//
// ?ViewController.m
// ?ui常用控件
//
// ?Created by lanou on 16/7/10.
// ?Copyright ? 2016年pingguo. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
@property(nonatomic,strong)UILabel*titleLabel;
@property(nonatomic,strong)UIButton*leftBtn;
@property(nonatomic,strong)UIButton*rightBtn;
@property(nonatomic,strong)UIImageView*myImageView;
@property(nonatomic,strong)NSArray*imageNames;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.imageNames=@[@"biaoqingdi",@"bingli",@"chiniupa",@"danteng",@"wangba"];
//創(chuàng)建并初始化按鈕圖片及文本
//表明文本的位置
self.titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(160,60,150,30)];
//文本內(nèi)容
self.titleLabel.text=@"biaoqingdi";
//將文本添加到視圖
[self.viewaddSubview:self.titleLabel];
//表明左按鈕的位置
self.leftBtn=[[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];
//關掉交互
self.leftBtn.userInteractionEnabled=NO;
//加載左按鈕的圖片
UIImage*leftImage=[UIImageimageNamed:@"left_disable"];
//左按鈕的背景及按下狀態(tài)
[self.leftBtnsetBackgroundImage:leftImageforState:(UIControlStateNormal)];
//將左按鈕添加到視圖
[self.viewaddSubview:self.leftBtn];
//表明圖片的位置
self.myImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];
//加載圖片
UIImage*image=[UIImageimageNamed:@"biaoqingdi"];
//設置myimageview顯示的圖片
self.myImageView.image=image;
//將圖片添加到視圖
[self.viewaddSubview:self.myImageView];
//以下同理
self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];
UIImage*rightImage=[UIImageimageNamed:@"right_normal"];
[self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];
[self.viewaddSubview:self.rightBtn];
//創(chuàng)立按鈕監(jiān)聽
[self.rightBtnaddTarget:selfaction:@selector(rightBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
[self.leftBtnaddTarget:selfaction:@selector(leftBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
}
-(void)rightBtnAction
{
//切換到下一張圖片
//獲取當前是第幾張圖片
NSIntegerindex=[self.imageNamesindexOfObject:self.titleLabel.text];
//不是為最后一張才切換到下一張
if(index<4) {
if(index==3) {
//改變右邊按鈕的顏色和關閉交互
self.rightBtn.userInteractionEnabled=NO;
UIImage*image=[UIImageimageNamed:@"right_disable"];
[self.rightBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
}
else{
//左邊按鈕和右邊按鈕都是在一個正常狀態(tài)下
//打開交互
self.leftBtn.userInteractionEnabled=YES;
self.rightBtn.userInteractionEnabled=YES;
UIImage*leftNormal=[UIImageimageNamed:@"left_normal"];
UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];
[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];
[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];
}
//將當前圖片與下一張圖片連接起來
NSString*nextTitle=self.imageNames[index+1];
//獲取后一張圖片的標簽
self.titleLabel.text=nextTitle;
//獲取后一張圖片的圖片內(nèi)容
self.myImageView.image=[UIImageimageNamed:nextTitle];
}
}
-(void)leftBtnAction
{
//切換到前一張圖片
//獲取當前是第幾張圖片
NSIntegerindex=[self.imageNamesindexOfObject:self.titleLabel.text];
//不是為第一張才切換到前一張
if(index>0) {
if(index==1) {
//左邊按鈕交互關閉刨秆,圖片切換
self.leftBtn.userInteractionEnabled=NO;
UIImage*image=[UIImageimageNamed:@"left_disable"];
[self.leftBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
}
else{
//左右兩邊按鈕都是正常狀態(tài)
self.leftBtn.userInteractionEnabled=YES;
self.rightBtn.userInteractionEnabled=YES;
UIImage*leftNormal=[UIImageimageNamed:@"left_normal"];
UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];
[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];
[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];
}
//將當前圖片與前一張圖片連接起來
NSString*beforeTitle=self.imageNames[index-1];
//獲取前一張圖片的標簽
self.titleLabel.text=beforeTitle;
//獲取前一張圖片的圖片內(nèi)容
self.myImageView.image=[UIImageimageNamed:beforeTitle];
}
}
-(void)btnClickLister
{NSLog(@"click btn");
}
-(void)demo {//按鈕UIButton
// ???UIButton ?*button=[UIButton buttonWithType:UIButtonTypeInfoDark];
UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(50,50,80,80)];
// frame表明了控件的
[buttonsetTitle:@"眼鏡哥"forState:UIControlStateNormal];
UIImage*image=[UIImageimageNamed:@"right_normal"];
[buttonsetBackgroundImage:imageforState:UIControlStateNormal];
button.backgroundColor=[UIColorredColor];
[buttonaddTarget:selfaction:@selector(btnClickLister)forControlEvents:UIControlEventTouchUpOutside];
//添加
[self.viewaddSubview:button];
UIImageView*imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)
];
UIImage*image1=[UIImageimageNamed:@"biaoqingdi"];
imageView.image=image1;
[self.viewaddSubview:imageView];
UILabel*label=[[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];
label.text=@"表情弟";
label.textAlignment=NSTextAlignmentCenter;
label.textColor=[UIColorredColor];
[self.viewaddSubview:label];
}
@end
//
// ?ViewController.m
//湯姆貓
//
// ?Created by lanou on 16/7/12.
// ?Copyright ? 2016年pingguo. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*tomCatView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// ???UIImageView ?*imageView=[UIImageView ?new];
//序列成動畫要播放的圖片數(shù)組
// ???imageView.animationImages
//動畫時長
// ???imageView.animationDuration
//動畫重復次數(shù)
// ???imageView.animationRepeatCount
//開始動畫
// ???[imageView startAnimating];
//結束動畫
// ???[imageView stopAnimating];
//是否正在執(zhí)行動畫
// ???[imageView ?isAnimating];
}
- (IBAction)eatBirdAction:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"eat"withCount:40];
/*
//創(chuàng)建可變數(shù)組images茅坛,負責存放要播放的圖片數(shù)組
NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<40; i++) {
//根據(jù)i來加載圖片,然后添加到可變數(shù)組images里面
NSString ?*imageName=[NSString ?stringWithFormat:@"eat_%02ld.jpg",i];
//根據(jù)格式化的圖片名加載圖片image
UIImage ?*image=[UIImage ?imageNamed:imageName];
//將圖片image添加到數(shù)組images中
[images ?addObject:image];
}
//設置動畫圖片數(shù)組
self.tomCatView.animationImages=images;
//設置動畫時長
self.tomCatView.animationDuration=40*0.075;
//設置動畫重復次數(shù)
self.tomCatView.animationRepeatCount=1;
//開始動畫
[self.tomCatView startAnimating]; ?*/
}
-(void)setTomCatAnimationWithName:
(NSString*)name ??withCount:(NSInteger)count
{
//判斷該動畫是否正在執(zhí)行
if([self.tomCatViewisAnimating]) {
return;
}
//創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組
NSMutableArray*images=[NSMutableArrayarray];
for(NSIntegeri=0; i
//根據(jù)i來加載圖片,然后添加到可變數(shù)組images里面
NSString*imageName=[NSStringstringWithFormat:@"%@_%02ld.jpg",name,i];
//根據(jù)格式化的圖片名加載圖片image
UIImage*image=[UIImageimageNamed:imageName];
//將圖片image添加到數(shù)組images中
[imagesaddObject:image];
}
//設置動畫圖片數(shù)組
self.tomCatView.animationImages=images;
//設置動畫時長
self.tomCatView.animationDuration=count*0.075;
//設置動畫重復次數(shù)
self.tomCatView.animationRepeatCount=1;
//開始動畫
[self.tomCatViewstartAnimating];
}
- (IBAction)drink:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"drink"withCount:81];
/* ?NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<81; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"drink_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=80*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ??*/
}
- (IBAction)pie:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"pie"withCount:24];
/* ?NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<24; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"pie_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=24*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ???*/
}
- (IBAction)scratch:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"scratch"withCount:56];
/* ????NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<56; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"scratch_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=56*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ??*/
}
- (IBAction)fart:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"fart"withCount:28];
/* ???NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<28; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"fart_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=28*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ??*/
}
- (IBAction)cymbal:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"cymbal"withCount:13];
/* ??NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<13; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"cymbal_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=13*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ???*/
}
- (IBAction)knockout:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"knockout"withCount:81];
/* ??NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<81; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"knockout_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=81*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ???*/
}
- (IBAction)angry:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"angry"withCount:26];
/* ?NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<26; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"angry_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=26*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ???*/
}
- (IBAction)stomach:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"stomach"withCount:34];
/* ?NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<34; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"stomach_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=34*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ???*/
}
- (IBAction)footleft:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"footLeft"withCount:30];
/* ?NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<30; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"footLeft_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=30*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating];*/
}
- (IBAction)footright:(UIButton*)sender {
[selfsetTomCatAnimationWithName:@"footRight"withCount:30];
/* NSMutableArray ?*images=[NSMutableArray ??array];
for (NSInteger ?i=0; i<30; i++) {
NSString ?*imageName=[NSString ?stringWithFormat:@"footRight_%02ld.jpg",i];
UIImage ?*image=[UIImage ?imageNamed:imageName];
[images ?addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=30*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; ?*/
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
p?????