UISlider_滑块
2015-11-21 09:35
381 查看
/
// 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];
}
// 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-Overal LTE Sequence
- UICollectionView
- 22.导航控制器UINavigationController
- UISearchBar介绍
- getRequestDispatcher()与sendRedirect()的区别
- UIImageView的contentMode属性
- LightOJ - 1188 Fast Queries(离线树状数组)
- SSH整合过程中出现的问题:could not fetch initial value for increment generatorat..
- 获取手机联系人+滚动选择器(MUI移动开发框架)
- ios UILabel显示html文本
- [Leetcode]Unique Path II
- iOS9 UIWindow rootViewController
- Qt---- 点击按钮调用另一个窗口Ui
- 基于UEditor的单独图片上传实现
- ios UIView 和 UIButton边框和阴影设置
- Elasticsearch Span Query跨度查询
- Android 中消息模型的四大核心对象:Message、MessageQueue、Looper、Handler
- GPUImage简单滤镜使用(二)
- 一个简单的创建圆角图像的UIImage扩展实现
- iOS UIScrollView实用之图片轮播 —— HERO博客