OC语法

作者: 丫丫丫丫丫0802 | 来源:发表于2016-07-12 22:43 被阅读0次

@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"];

//定义标签位置与名称

self.titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(50,50,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*image1= [UIImageimageNamed:@"biaoqingdi"];

self.myImageView.image=image1;

//显示相框图片

[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)leftBtnAction

{

NSUIntegerindex = [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;

self.rightBtn.userInteractionEnabled=YES;

UIImage*leftNormal= [UIImageimageNamed:@"left_normal"];

UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];

[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];

[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];

}

NSString*preTitle=self.imageNames[index-1];

self.titleLabel.text= preTitle;

self.myImageView.image=[UIImageimageNamed:preTitle];

}

}

-(void)rightBtnAction

{

//切换到下一张图片

//获取当前是第几张图片

NSUIntegerindex = [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;

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;

//根据名称加载图片

self.myImageView.image= [UIImageimageNamed:nextTitle];

}

}

- (void)didReceiveMemoryWarning{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be

recreated.

}

@end

相关文章

  • IOS暑假小学期实训 第1天 总结 “ OC基本语法”&&“

    2016/07/09 OC基本语法 // // main.m // OC基本语法 // // Created by...

  • 代码

    1.oc基本语法 // // main.m // oc基本语法 // // Created by lanou on...

  • 杂记

    OC语法问题 OC语法细节:不允许直接修改OC对象的结构体属性的成员 比如:self.scrollView.con...

  • oc基本语法

    // oc基本语法 // 整形 NSInteger a = 10; // NSLog是oc里面的...

  • 在Objective-C代码里面使用C++代码

    OC文件,不认识C++语法,只认识OC语法和C语法,使用了C++语法编译会报错 解决:后缀名改为.mm,例如把ma...

  • 无标题文章

    OC基础语法 //整型 NSIntegera =10; //NSLog是OC里面的打印函数 NSLog(@"a =...

  • OC之01基础之基础语法

    01 语法概述 不妨将OC说成是面向对象的C语言,因为OC是在C语言的基础是建立的,而且在OC的语法中是完全...

  • OC . 语法

    一、点语法作用1、方便其他语言程序员很快转到OC开发2、程序设计简单化3、隐藏了内存管理细节4、隐藏多线程、同步、...

  • OC语法

    @interfaceViewController() //标题标签 @property(nonatomic,str...

  • OC语法

    //标题标签 @property(nonatomic,strong)UILabel*titleLabel; //左...

网友评论

      本文标题:OC语法

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