In our development of the project, we often encounter such a function, such as adjusting the brightness, or adjust the current screen font size,
In fact, this function is very well implemented,
The specific code is as follows:
First, declare member variables
1 {2 UIView *_view; 3 BOOL Ishidden; 4 UISlider *_slider; 5 UISlider *_twoslider; 6 float value; 7 UILabel *_label; 8 Nsinteger fontSize; 9 }
Second, create the font you need to change, a label or other control, feel free to
1_label = [[UILabel alloc]initwithframe:cgrectmake ( -, -, Mainscreen_width- -, the)];2_label.textalignment =Nstextalignmentcenter;3_label.textcolor =[Uicolor Whitecolor];4_label.text =@"Bumblebee";5FontSize = the;6_label.font = [Uifont systemfontofsize: the];7[ImageView Addsubview:_label];
Third, create a slider, and the brightness and font size of the screen associated with the slider
1_slider.backgroundcolor = Rgbacolor (239,239,239,1);2_slider.value =0.5;3_slider.minimumvalue =0.01;4_slider.maximumvalue =1.0;5_slider.minimumtracktintcolor = [Uicolor Greencolor];//the color of the streak6_slider.maximumtracktintcolor = [Uicolor Whitecolor];//colors that are not crossed7 [_slider addtarget:self Action: @selector (Slidervaluechange:) forcontrolevents:uicontroleventvaluechanged];8 [_view Addsubview:_slider];9 Ten_twoslider = [[UISlider alloc]initwithframe:cgrectmake ( *, -, Mainscreen_width- -, -)]; One_twoslider.backgroundcolor = Rgbacolor (239,239,239,1); A_twoslider.minimumvalue =1; -_twoslider.maximumvalue = -; -_twoslider.value = -; the_twoslider.minimumtracktintcolor = [Uicolor Greencolor];//the color of the streak -_twoslider.maximumtracktintcolor = [Uicolor Whitecolor];//colors that are not crossed - [_twoslider addtarget:self Action: @selector (Twoslidervaluechange:) forControlEvents: Uicontroleventvaluechanged]; -[_view Addsubview:_twoslider];
Third, the realization of the specific click method
1 //ways to control screen brightness2-(void) Slidervaluechange: (UISlider *) Sender3 {4 [[UIScreen mainscreen]setbrightness:sender.value];5 }6 7 //ways to control font size8-(void) Twoslidervaluechange: (UISlider *) Sender9 {Ten_label.font =[Uifont SystemFontOfSize:sender.value]; One}
In this case, the specific function is realized, you can drag the slider to control the brightness of the screen and the size of the label font;
Specific implementations such as:
Note: Adjust the screen brightness method, need to be real machine to see! Get the current system screen brightness method, the above method is specific, you can see!
Adjust screen brightness, adjust font size