代码创建图片轮换; 代码创建控件时,如何将控件定义成属性

来源:互联网 发布:pro tools mac 破解版 编辑:程序博客网 时间:2024/06/05 09:44

代码创建图片播放

#import "ViewController.h"

#define kLength 15

@interface ViewController ()

 

@property(nonatomicweak)UIImageView *myImage;

@property(nonatomicweak)UILabel *myLabel;

@property(nonatomic,weakUISlider *mySlider;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    //创建image控件

//1 创建控件

     UIImageView  *myImg[[UIImageView alloc]init];

    self.myImage = myImg    

    //2添加控件

    [self.view addSubview:self.myImage];

    //3设置按钮位置

    self.myImage.frame = CGRectMake(60150200200);

    //4默认状态下属性

    self.myImage.image = [UIImage imageNamed:@"0"];

    

    //创建lable控件记录页数

//1创建控件

 UILabel *myLbl = [[UILabel alloc]init];

    self.myLabel = myLbl;

    //2添加控件

    [self.view addSubview:self.myLabel];

    //3设置控件位置

    self.myLabel.frame = CGRectMake(608020050);

    //4默认状态下属性

    self.myLabel.text = [NSString stringWithFormat:@"0/%d",kLength];

    self.myLabel.textAlignment = NSTextAlignmentCenter;

    

    //创建progress控件

//1创建控件

   UISlider *mySlid = [[UISlider alloc]init];

 

self.mySlider = mySlid   

 //2添加控件

    [self.view addSubview:self.mySlider];

    //3设置控件位置

    self.mySlider.frame = CGRectMake(3040026030);

    //4添加监听事件

    [self.mySlider addTarget:self action:@selector(btnSlider) forControlEvents:UIControlEventValueChanged];

    //5默认状态下属性

    self.mySlider.minimumValue = 0;

    self.mySlider.maximumValue = kLength;

    

}

-(void)btnSlider

{

    //slider当前值取整数

    NSString *nowValue = [NSString stringWithFormat:@"%.f",self.mySlider.value];

    self.myLabel.text = [NSString stringWithFormat:@"%@/%d", nowValue, kLength];

    self.myImage.image = [UIImage imageNamed:nowValue];

    

}

 

 

@end

 

0 0
原创粉丝点击