简单的介绍了OC语言的用途和历史,是一种基于苹果产品——IOS系统产品的编程语言,能够智能有效的写出符合而实际的App,并且能够在苹果各个产品上的虚拟器进行运行,不需要对该程序进行实地的运行,减少时间的消耗,节约成本。
这是对图片编辑器的编写和操作,将一句句较短的语句根据语法进行排序,完成整个程序的编写;这些语句有:[self.view addSubview:定义名](将你定义的添加到视图上)、[button.frame = CGRectMake(CGFloat x,CGFloat y,CGFloat width,CGFloat height)];(frame表明了定义控件的坐标和宽高)等等。
#import"ViewController.h"
@interface ViewController ( )
//标题标签
@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"];
//创建并初始化标签文本
self.titlelabel=[[UILabelalloc]initWithFrame:CGRectMake(150,300,150,30)];
//设置标签文本
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"];
//给左边按钮设置背景图片
[self.leftBtnsetBackgroundImage:leftImageforState:
(UIControlStateNormal)];
//设置左边按钮显示的图片
[self.viewaddSubview:self.leftBtn];
//创建并初始化相框
self.myImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];
//根据名字加载图片
UIImage*image=[UIImageimageNamed:@"biaoqingdi"];
self.myImageView.image=image;
//设置myImageView显示的图片
[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];
[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{
//左边按钮和右边按钮都是在一个正常状态
self.leftBtn.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;
//设置相框显示的下一张图片
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{
//左右两边按钮都是正常状态
self.leftBtn.userInteractionEnabled=YES;
//设置左右按钮的平常的图片
UIImage*leftNormal=[UIImageimageNamed:@"left_normal"];
UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];
//设置左右按钮的背景图片以及状态
[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];
[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];
//启用右按钮的运动状态
self.rightBtn.userInteractionEnabled=YES;
}
NSString*preTitle=self.imageNames[index-1];
self.titlelabel.text=preTitle;
self.myImageView.image=[UIImageimageNamed:preTitle];
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end