ios-How to change a picture into blue

Source: Internet
Author: User

In the previous development process, encountered such a small problem: To button set a picture, the picture is gray, the artwork does not have a problem, the method to set the button is also very simple, a code to do, but run the time but found that the picture has become blue for no reason. Later I studied the discovery, in some controls to set the picture will default to the image rendered blue, to find the problem, it is good ending, the solution is as follows:

    UIButton *loginbtn = [[UIButton alloc]initwithframe:cgrectmake (+, +, +)];    loginbtn.showstouchwhenhighlighted = YES;    UIImage *loginimg = [UIImage imagenamed:@ "Login"];    loginimg = [loginimg imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];    [Loginbtn setimage:loginimg forstate:uicontrolstatenormal];    [Self.view ADDSUBVIEW:LOGINBTN];

-(UIImage *) Imagewithrenderingmode: (uiimagerenderingmode) renderingmode

This method is used to set the rendering mode of the image.

Uiimagerenderingmodealwaysoriginal This enumeration value is to declare that the picture is to be displayed as it was originally, and that it does not need to be rendered into another color
Ok! The problem ends. Put this little problem here to prevent the next encounter and forget how to solve!

Incidentally, if your artwork doesn't give you the button's size, just gives you the button's picture, then you can directly take the image size, then set the button to the same size as the picture

    UIButton *loginbtn = [UIButton buttonwithtype:uibuttontypecustom];    loginbtn.showstouchwhenhighlighted = YES;    UIImage *loginimg = [UIImage imagenamed:@ "Login"];    loginimg = [loginimg imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];     [Loginbtn setimage:loginimg forstate:uicontrolstatenormal];    Cgsize size = loginbtn.currentimage.size;//The dimension of the image taken to the button    Loginbtn.frame = CGRectMake (+, Size.width, Size.Height);    [Self.view ADDSUBVIEW:LOGINBTN];


ios-How to change a picture into blue

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.