//
//ViewController.m
//UI常用控件
//
//Created by lanou on 16/7/10.
//Copyright©2016年lanou. 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"];
//定义标签位置与名称
self.titleLabel= [[UILabelalloc]initWithFrame:CGRectMake(150,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:leftImage
forState:(UIControlStateNormal)];
[self.viewaddSubview:self.leftBtn];
//显示相框名称
self.myImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];
UIImage*image = [UIImageimageNamed:@"biaoqingdi"];
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];
//按钮的监听
[self.rightBtnaddTarget:selfaction:@selector(rightBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
//点击右边按钮时,按钮状态upinside
[self.leftBtnaddTarget:selfaction:@selector(leftBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
//点击左边按钮时,按钮状态upinside
}
-(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:image
forState:(UIControlStateNormal)];
}else{
//左边按钮和右边按钮都是在一个正常状态
self.leftBtn.userInteractionEnabled=YES;
self.rightBtn.userInteractionEnabled=YES;
UIImage*leftNormal = [UIImageimageNamed:@"left_normal"];
//左边按钮的正常状态下的图片
UIImage*rightNormal =[UIImageimageNamed:@"right_normal"];
//左边按钮的正常状态下的图片
[self.leftBtnsetBackgroundImage:leftNormal
forState:(UIControlStateNormal)];
//让左按钮的正常状态在屏幕上显示出来
[self.rightBtnsetBackgroundImage:rightNormal
forState:(UIControlStateNormal)];
//让右按钮的正常状态在屏幕上显示出来
}
NSString*nextTitle =self.imageNames[index+1];
//创建一个字符串类型的下一个标题
self.titleLabel.text= nextTitle;
//titileLabel的文本是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:image
forState:(UIControlStateNormal)];
}else{
//左边按钮和右边按钮都是在一个正常状态
self.leftBtn.userInteractionEnabled=YES;
self.rightBtn.userInteractionEnabled=YES;
UIImage*leftNormal = [UIImageimageNamed:@"left_normal"];
UIImage*rightNormal =[UIImageimageNamed:@"right_normal"];
[self.leftBtnsetBackgroundImage:leftNormal
forState:(UIControlStateNormal)];
//给左边的按钮设置图片
[self.rightBtnsetBackgroundImage:rightNormal
forState:(UIControlStateNormal)];
//给右边的按钮设置图片
}
NSString*preTitle =self.imageNames[index-1];
self.titleLabel.text= preTitle;
self.myImageView.image = [UIImage imageNamed:preTitle];
}
}
-(void)btnClickLister
{
NSLog(@"click btn");
}
-(void)demo {
//UIView *view =[u]
//按钮UIButton
//UIButton *button =[UIButtonbuttonWithType:UIButtonTypeInfoDark];
UIButton*button = [[UIButtonalloc]initWithFrame:CGRectMake(20,50,80,80)];
//frame表明了控件的坐标和宽高(CGRect类型)
//[button setTitle:@"阿陶" forState:UIControlStateNormal];
UIImage*image = [UIImageimageNamed:@"left_normal"];
//根据名字加载图片
[buttonsetBackgroundImage:image forState:UIControlStateNormal];
//给按钮设置背景图片
//button.backgroundColor = [UIColor redColor];
//按钮的监听
[buttonaddTarget:selfaction:@selector(btnClickLister)
forControlEvents:UIControlEventTouchUpInside];
//添加到视图上面
[self.viewaddSubview:button];
//相框UIImageView
UIImageView*imageview = [[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)];
UIImage*image1 = [UIImageimageNamed:@"biaoqingdi"];
//设置imageView显示的图片
imageview.image= image1;
[self.viewaddSubview:imageview];
//标签UILabel
UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];
//设置标签文本
label.text=@"呵呵";
//设置居中方式
label.textAlignment=NSTextAlignmentCenter;
label.textColor= [UIColorredColor];
[self.view addSubview:label];}
@end
Ads",".�q�Ē�v