Adjust screen brightness, adjust font size

Source: Internet
Author: User

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

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.