将slider滑块从横着变为竖着的时候坐标变换的计算

//
//  ViewController.m
//  imageview添加按钮
//
//  Created by hehe on 15/9/22.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "ViewController.h"
#define ws self.view.bounds.size.width
#define hs self.view.bounds.size.height
@interface ViewController ()
{
    int x,y,w,l;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    float w1 = self.view.bounds.size.width;
    float h1 = self.view.bounds.size.height;
    NSLog(@"宽=%.1f,高=%.1f",w1,h1);
    w=hs; //480  长度
    l=50;//宽
    x=ws-hs/2;//x位置
    y=hs/2-l/2;//y位置


    [self creatSlider];
    
    [self creatSlider1];
    
}
#pragma mark -------实现button的onClick方法
- (void)onClick:(UIButton *)btn
{
    static int i = 0;
    NSLog(@"%d",i++);
}

#pragma mark    ------------------------滑块
- (void)creatSlider1
{
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(x, y, w, l)];
    
    [self.view addSubview:slider];
    
    //设置最小值
    slider.minimumValue = 0;
    
    slider.maximumValue = 100;
    
    slider.value = 20;
    
    slider.tintColor = [UIColor greenColor];
    
    slider.minimumTrackTintColor = [UIColor redColor];
    
    slider.maximumTrackTintColor = [UIColor purpleColor];
    
    slider.thumbTintColor = [UIColor blueColor];
    //@property(nonatomic,retain) UIColor *thumbTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;   ????????????
    
    slider.minimumValueImage = [UIImage imageNamed:@"min"];
    slider.maximumValueImage = [UIImage imageNamed:@"max"];
    
    [slider setThumbImage:[UIImage imageNamed:@"min"] forState:UIControlStateHighlighted];
    
    
    
    //注册事件
    [slider addTarget:self action:@selector(onSliderChanged1:) forControlEvents:UIControlEventValueChanged];
    
    slider.continuous = NO;
}

- (void)onSliderChanged1:(UISlider *)slider
{
    NSLog(@"slider1 = %f",slider.value);
}


#pragma mark    ------------------------滑块
- (void)creatSlider
{
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(x, y, w, l)];
    
    [self.view addSubview:slider];
    
    //设置最小值
    slider.minimumValue = 0;
    
    slider.maximumValue = 100;
    
    slider.value = 20;
    
    slider.tintColor = [UIColor greenColor];
    
    slider.minimumTrackTintColor = [UIColor redColor];
    
    slider.maximumTrackTintColor = [UIColor purpleColor];
    
    slider.thumbTintColor = [UIColor blueColor];
    //@property(nonatomic,retain) UIColor *thumbTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;   ????????????
    
    slider.minimumValueImage = [UIImage imageNamed:@"min"];
    slider.maximumValueImage = [UIImage imageNamed:@"max"];
    
    [slider setThumbImage:[UIImage imageNamed:@"min"] forState:UIControlStateHighlighted];
    
    slider.transform=CGAffineTransformMakeRotation(M_PI_2);

    
    //注册事件
    [slider addTarget:self action:@selector(onSliderChanged:) forControlEvents:UIControlEventValueChanged];
    
    slider.continuous = NO;
}

- (void)onSliderChanged:(UISlider *)slider
{
    NSLog(@"slider = %f",slider.value);
}

@end

转载于:https://www.cnblogs.com/wanghengheng/p/4829936.html

你可能感兴趣的:(将slider滑块从横着变为竖着的时候坐标变换的计算)