The sound display effect produced by UISlider

Source: Internet
Author: User

Simply demonstrate the effect and implement it directly in the Ingress class

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //Override point for customization after application launch.Self.window.backgroundColor =[Uicolor Whitecolor];        [Self.window makekeyandvisible]; UISlider*slider =[[UISlider alloc] init]; Slider.center= Cgpointmake ( the, -); Slider.bounds= CGRectMake (0,0, -, -); Slider.tag= -; Slider.minimumvalue=0; Slider.maximumvalue= -; Slider.minimumtracktintcolor= [Uicolor Greencolor];//A color that has been slippedSlider.maximumtracktintcolor = [Uicolor Bluecolor];//the color of the slider barSlider.value = -;    [Slider addtarget:self action: @selector (Changevoice:) forcontrolevents:uicontroleventvaluechanged];        [Self.window Addsubview:slider]; _imageview=[[Uiimageview alloc] init]; _imageview.center= Cgpointmake ( -, -); _imageview.bounds= CGRectMake (0,0, -, -); _imageview.image= [UIImage imagenamed:@"Mid.png"];    [Self.window Addsubview:_imageview]; //[Nstimer scheduledtimerwithtimeinterval:0.01 target:self selector: @selector (addvalue:) Userinfo:slider repeats: YES];UIButton*BTN =[UIButton Buttonwithtype:uibuttontypesystem]; Btn.frame= CGRectMake (0,0, -, -);    [_imageview ADDSUBVIEW:BTN]; _imageview.userinteractionenabled=YES;    [Btn addtarget:self Action: @selector (Voicechange) forcontrolevents:uicontroleventtouchupinside]; returnYES;}//The timer method, the sound automatically increases, but at this time although the value of the slider changes, but does not trigger the method- (void) AddValue: (Nstimer *) timer{UISlider*slider = (UISlider *) [Timer userInfo]; if(Slider.value < -) {Slider.value+=0.1; }}//the high and low levels of sound can be represented by icons.- (void) Changevoice: (UISlider *) slider{if(Slider.value = =0) {_imageview.image= [UIImage imagenamed:@"None.png"]; return; }    if(Slider.value < -) {_imageview.image= [UIImage imagenamed:@"Low.png"]; return; }    if(Slider.value < -) {_imageview.image= [UIImage imagenamed:@"Mid.png"]; return; }    if(Slider.value <= -) {_imageview.image= [UIImage imagenamed:@"High.png"]; }}//when the sound is not 0, clicking on the sound icon always resets the sound to 0, and when the icon is clicked again, the sound is restored- (void) voicechange{UISlider*slider = (UISlider *) [Self.window Viewwithtag: -]; Static intCount =0; Count++; if(Count%2!=0) {_voicevalue= Slider.value;//remember the last sound.Slider.value =0; }    Else    {        if(Slider.value! =0)//The sound adjustment is no longer 0 before the sound is restored, using recursion{[Self voicechange]; Count=0; } slider.value=_voicevalue; }}@end

The timer in the code would have been like a mock-up of the effect of making the sound auto-lifted, and it was not possible to demonstrate it, but to think that the slider would have to interact with the user in order to show the meaning of its existence.

The sound display effect produced by UISlider

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.