标签:ui 属性 代码创建控件 uiimage uislider
代码创建图片播放
#import "ViewController.h"
#define kLength 15
@interface ViewController ()
@property(nonatomic, weak)UIImageView *myImage;
@property(nonatomic, weak)UILabel *myLabel;
@property(nonatomic,weak) UISlider *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(60, 150, 200, 200);
//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(60, 80, 200, 50);
//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(30, 400, 260, 30);
//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
标签:ui 属性 代码创建控件 uiimage uislider
原文地址:http://blog.csdn.net/u010438187/article/details/45586135