UISlider_滑块

/
//  SecondViewController.m
//  UISlider_ 滑块
//
//  Created by apple on 15/11/20.
//  Copyright © 2015 shuo. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()
@property ( nonatomic , retain ) UILabel *sliderValueLabel; // 显示 value
@property ( nonatomic , retain ) UISlider *slider; // 滚动条
@property ( nonatomic , retain ) UILabel *xLabel; // 文字标签
@property ( assign , nonatomic ) CGFloat initialFontSize; // 文字缩放尺寸

@end

@implementation SecondViewController

- (
void )viewDidLoad {
    [
super viewDidLoad ];
   
   
self . view . backgroundColor =[ UIColor whiteColor ];
   
UIButton *button1 =[ UIButton buttonWithType : UIButtonTypeCustom ];
    button1.
frame = CGRectMake ( 100 , 570 , 180 , 30 );
    [button1
setTitle : @" 回到主页 " forState : UIControlStateNormal ];
    button1.
backgroundColor =[ UIColor purpleColor ];
    [
self . view addSubview :button1];
    [button1
addTarget : self action : @selector (buttonAction1:) forControlEvents : UIControlEventTouchUpInside ];
   
//---------------------------------------------------------------
  
       
// 显示 sliders 值的 label
   
self . sliderValueLabel =[[ UILabel alloc ] initWithFrame : CGRectMake ( 20 , 30 , 30 , 30 )];
   
self . sliderValueLabel . backgroundColor =[ UIColor cyanColor ];
   
self . sliderValueLabel . text = @"0" ;
    [
self . view addSubview : self . sliderValueLabel ];
   
   
self . slider =[[ UISlider alloc ] initWithFrame : CGRectMake ( 100 , 30 , 200 , 40 )];
   
self . slider . minimumValue = 0 ; // 最小值
   
self . slider . maximumValue = 25 ; // 最大值
   
self . slider . thumbTintColor =[ UIColor colorWithRed : arc4random ()% 256 / 255.0 green : arc4random ()% 256 / 255.0 blue : arc4random ()% 256 / 255.0 alpha : 1.0 ];
   
    [
self . slider addTarget : self action : @selector (sliderValueChange) forControlEvents : UIControlEventValueChanged ];
   
    [
self . view addSubview : self . slider ];
   
//--------------------- 文字标签 -------------------------------
   
   
self . xLabel =[[ UILabel alloc ] initWithFrame : CGRectMake ( 0 , 100 , 375 , 400 )];
   
self . xLabel . backgroundColor =[ UIColor   cyanColor ];
    self.xLabel.text =@"提莫";
    //--????????————————标签文字居中貌似被废---
     self . xLabel . textAlignment = UITextAlignmentCenter ;
   
self . initialFontSize = self . xLabel . font . pointSize ;
   
NSLog ( @"initialFontSize  =%.2f" , self . initialFontSize );
    [
self . view addSubview : self . xLabel ];

   }
- (
void )sliderValueChange{
   
NSLog ( @"sliderValueChange" );
   
// 更新 sliderValueChange 的值
   
self . sliderValueLabel . text =[[ NSString alloc ] initWithFormat : @"%.0f" , self . slider . value ];
   
// 缩放 xlabel 内容
   
CGFloat newFontSize = self . initialFontSize *( self . slider . value + 1 );
   
NSLog ( @"newFontSize =%.2f" ,newFontSize);
   
   
self . xLabel . font = [ self . xLabel . font fontWithSize :newFontSize];
   
   
   
   
   
}
    -(
void )dealloc{
       
        [
_sliderValueLabel release ];
        [
_slider release ];
        [_xLabel release ];
        [ super dealloc ];
       
}


- (
void )buttonAction1:( UIButton *)btn{
  

    [
self dismissViewControllerAnimated : YES completion :^{
       
       
NSLog ( @" 回到主页 " );
    }];
   
   // 控制标签的 value 更新
   
UISlider *sli1 =( UISlider *)sli;
   self.label.text =[NSString stringWithFormat:@"%.2f",sli1.value];
   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值