//
// Rootview.m
// UI - 05 UIcontroller
//
// Created by dllo on 15/11/12.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "Rootview.h"
@interface Rootview()
@property (nonatomic, retain) UIImageView *imagev;
@end
@implementation Rootview
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createView];
}
return self;
}
- (void) createView
{
self.backgroundColor = [UIColor lightGrayColor];
UISlider *sileder = [[UISlider alloc]initWithFrame:CGRectMake(50, 500, 200, 50)];
//注意UIControlEventValueChanged 改变值的时候触发
[sileder addTarget:self action:@selector(sliderAct:) forControlEvents:UIControlEventValueChanged];
//当前值设定 (园钮位置改变);
sileder.value = 0.5;
//改变最大值,最小值
sileder.maximumValue = 30;
// sileder.minimumValue = 0;
//轨迹左边颜色
sileder.minimumTrackTintColor = [UIColor blueColor];
//轨迹右边颜色
sileder.maximumTrackTintColor = [UIColor orangeColor];
sileder.thumbTintColor = [UIColor greenColor];
[self addSubview:sileder];
[sileder release];
NSMutableArray *imageArr = [NSMutableArray array];
self.imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
for (NSInteger i = 1; i < 17; i++) {
// 拼接图片的名字
// 注意!!!查看图片的序号是1还是01/001 %02ld, 占2位 前一位如果空了自动补零
// 若序号是001的形式 %03ld
NSString *fileName = [NSString stringWithFormat:@"happy_%04ld.png", i];
// 创建uiimage类型的对象
UIImage *image = [UIImage imageNamed:fileName];
[imageArr addObject:image];
}
for (NSInteger i = 1 ; i < 26; i++) {
NSString *c = [NSString stringWithFormat:@"heart_BG_%04ld.png", i];
UIImage *image = [UIImage imageNamed:c];
[imageArr addObject:image];
}
// for (NSInteger i = 1 ; i < 5; i++) {
// NSString *c = [NSString stringWithFormat:@"heart_broken_%04ld.png", i];
// UIImage *image = [UIImage imageNamed:c];
// [imageArr addObject:image];
// }
for (NSInteger i = 1 ; i < 16; i++) {
NSString *c = [NSString stringWithFormat:@"heart_jump_%04ld.png", i];
UIImage *image = [UIImage imageNamed:c];
[imageArr addObject:image];
}
for (NSInteger i = 1 ; i < 29; i++) {
NSString *c = [NSString stringWithFormat:@"hold_hand_%04ld.png", i];
UIImage *image = [UIImage imageNamed:c];
[imageArr addObject:image];
}
for (NSInteger i = 33 ; i < 47; i++) {
NSString *c = [NSString stringWithFormat:@"hold_heart_%04ld.png", i];
UIImage *image = [UIImage imageNamed:c];
[imageArr addObject:image];
}
for (NSInteger i = 1 ; i < 25; i++) {
NSString *c = [NSString stringWithFormat:@"hold_heart_B_%02ld.png", i];
UIImage *image = [UIImage imageNamed:c];
[imageArr addObject:image];
}
// 要播放的图片数组
self.imagev.animationImages = imageArr;
self.imagev.image = [UIImage imageNamed:@"happy_0001.png"];
[self addSubview:self.imagev];
// 播放时间
self.imagev.animationDuration = sileder.maximumValue - sileder.value ;
// 重复次数 - 默认是0 即无线循环
// self.imagev.animationRepeatCount = 2;
// 播放动画
[self.imagev startAnimating];
// 停止播放
// [imagev stopAnimating];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 300, 100, 30);
button.backgroundColor = [UIColor redColor];
[button setTitle:@"结束" forState:UIControlStateNormal];
[button addTarget:self action:@selector(stop:) forControlEvents: UIControlEventTouchUpInside];
[self addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(180, 300, 100, 30);
button1.backgroundColor = [UIColor orangeColor];
[button1 setTitle:@"开始" forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(start:) forControlEvents: UIControlEventTouchUpInside];
[self addSubview:button1];
UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"王宁", @"杨忠祥", @"初旭", nil]];
segmentC.frame = CGRectMake(10, 400, 300, 30);
//边框颜色
segmentC.tintColor = [UIColor redColor];
//背景颜色
segmentC.backgroundColor = [UIColor blackColor];
//设置选择状态 选择第几个背景变蓝
segmentC.selectedSegmentIndex = 0;
//插入
[segmentC insertSegmentWithTitle:@"狼" atIndex:1 animated:NO];
//修改
[segmentC setTitle:@"由盛焱" forSegmentAtIndex:0];
//插入带图片的segment
UIImage *image = [UIImage imageNamed:@"1.png"];
//图片渲染
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[segmentC insertSegmentWithImage:image atIndex:2 animated:YES];
[segmentC addTarget:self action:@selector(seAction:) forControlEvents: UIControlEventValueChanged ];
[self addSubview:segmentC];
[segmentC release];
}
- (void)seAction:(UISegmentedControl *)sender
{
NSLog(@" %ld", sender.selectedSegmentIndex);
}
- (void)start:(UIButton *)sender
{
[self.imagev startAnimating];
}
- (void)stop:(UIButton *)sender
{
[self.imagev stopAnimating];
}
- (void)sliderAct: (UISlider *)sender {
//也可以用tag 来实现 uiimageview *a = (uiimageview *)[self viewWIthtag : ]
self.imagev.animationDuration = sender.maximumValue - sender.value + 0.01;
[self.imagev startAnimating];
// NSLog( @"当前滚动条的值为:%f", sender.value);
}
@end