//
// RootViewController.m
// UI 05 __ UIControl
//
// Created by dllo on 15/12/14.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface RootViewController ()
@property(nonatomic ,retain)AVAudioPlayer *player;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor yellowColor];
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 50)];
textField.layer.borderWidth=1;
textField.layer.cornerRadius=10;
[self.view addSubview:textField];
[textField release];
// 添加一个触发的方法
// 监控输入状态
[textField addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
UIStepper *steppre=[[UIStepper alloc]initWithFrame:CGRectMake(100, 240, 100, 30)];
[self.view addSubview:steppre];
[steppre release];
steppre.tintColor=[UIColor orangeColor];
[steppre addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
// 设置最大值
steppre.maximumValue=200;
// 设置最小值
steppre.minimumValue=1;
// 设置每次修改的值
steppre.stepValue=2;
// 找音乐文件路径
NSString *path=[[NSBundle mainBundle]pathForResource:@"荒木毬菜 - 春夏秋冬 [mqms]" ofType:@"m4a"];
NSURL *url=[NSURL fileURLWithPath:path];
NSLog(@"%@",url);
self.player=[[AVAudioPlayer alloc]
initWithContentsOfURL:url error:nil];
[self.player play];
//
UISlider * slidre=[[UISlider alloc]initWithFrame:CGRectMake(100, 500, 200, 50)];
slidre.backgroundColor=[UIColor whiteColor];
[self.view addSubview:slidre];
// 右线的颜色
slidre.minimumTrackTintColor=[UIColor orangeColor];
// 线的颜色
slidre.maximumTrackTintColor=[UIColor blackColor];
// 原点颜色
slidre.thumbTintColor=[UIColor whiteColor];
[slidre release];
UISwitch *switc=[[UISwitch alloc]initWithFrame:CGRectMake(100, 400, 200, 500)];
switc.backgroundColor=[UIColor orangeColor];
[self.view addSubview:switc];
switc.tintColor=[UIColor whiteColor];
[switc addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[switc release];
}
-(void)changeValue:(UITextField *)textField{
NSLog(@"%@",textField.text);
}
-(void)stepperAction:(UIStepper *)steppre{
NSLog(@"%f",steppre.value);
self.player.volume=steppre.value;
}
-(void)change:(UISwitch *)switc{
NSLog(@"%d",switc.on);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end