UI基础控件一

UIImageView、UILabel比较轻量级,因为大多数都做展示使用,并不需要什么特殊的操作,没有像UIButton类的组件继承UIControl,所以拥有的事件也比较少,而UISlider、UIStepper、UISwitch这些常用的操作性的控件都继承自UIControl,拥有丰富的事件。

控制器头文件

#import <UIKit/UIKit.h>


@interface cooljuneViewController :UIViewController


@property (weak, nonatomic) IBOutletUIImageView *imgaeView;


@property (weak, nonatomic) IBOutletUILabel *imageTitleView;


@property (weak, nonatomic) IBOutletUIStepper *imageStepper;


@property (weak, nonatomic) IBOutletUISlider *imageSlider;


@property (weak, nonatomic) IBOutletUILabel *imageNoView;


- (IBAction)stepClick:(UIStepper *)sender;

- (IBAction)clickSlider:(UISlider *)sender;

- (IBAction)modeNight:(UISwitch *)sender;



@end

控制器.m文件

- (void)viewDidLoad

{

    [superviewDidLoad];

//加载plist文件

   NSBundle *bunle=[NSBundlemainBundle];

    //根据文件类型和文件名加载plist文件

   NSString *path= [bunlepathForResource:@"photo"ofType:@"plist"];


    self.imagesData=[NSArrayarrayWithContentsOfFile:path];   

    //初始化总数

    self.imageNoView.text=[NSStringstringWithFormat:@"1/%d",self.imagesData.count];

    //初始化slider

    self.imageSlider.minimumValue=1;

    self.imageSlider.maximumValue=self.imagesData.count;

    

    //获取第一个图片的值

   NSDictionary *dict=self.imagesData[0];

   UIImage *firstImage=[UIImageimageNamed:dict[@"icon"]];

    

    //设置第一张图片UIImageView

   self.imgaeView.image=firstImage;

    //UILabel

   self.imageTitleView.text=dict[@"title"];

    

   //初始化UIStepper

    self.imageStepper.maximumValue=self.imagesData.count;

    self.imageStepper.minimumValue=1;

    self.imageStepper.stepValue=1;

    self.imageStepper.value=1;

    

}

//监听UISlider控件

- (IBAction)clickSlider:(UISlider *)sender {

    //获取当前值

   int index= self.imageSlider.value;

   NSDictionary *dict= self.imagesData[index-1];

   UIImage *currentImage=[UIImageimageNamed:dict[@"icon"]];

    

   self.imgaeView.image=currentImage;

   self.imageTitleView.text=dict[@"title"];

   self.imageNoView.text=[NSStringstringWithFormat:@"%d/%d",index,self.imagesData.count];

    

    

}

//监听UISwitch控件

- (IBAction)modeNight:(UISwitch *)sender {

    self.view.backgroundColor=sender.isOn?[UIColorgrayColor]:[UIColorwhiteColor];

}

//监听UIStepper控件

- (IBAction)stepClick:(UIStepper *)sender {

   int index=self.imageStepper.value;

   NSDictionary *dict=self.imagesData[index-1];

   UIImage *image=[UIImageimageNamed:dict[@"icon"]];

   self.imgaeView.image=image;

}



你可能感兴趣的:(UILabel,UISwitch,UISlider,UIImageView,UIStepper)