Tips for iOS development and tips for iOS development

Source: Internet
Author: User

Tips for iOS development and tips for iOS development
The background color of the system navigationBar needs to be modified during code writing, at first, I used barTintColor to modify it, but I couldn't help it. When the system clicked the button, there was a rendering highlight effect. After a long time, I didn't achieve what I wanted, finally, I gave up using the color to do this. I checked the swift API and found that I could also use images. I am sorry to find the UI. (it is not appropriate to find the UI cut image in my demo, I have to change the color to the image)

The text begins:

First, copy the OC code.

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Swift code available

Func imageWithColor (color: UIColor)-> (UIImage ){
Let rect = CGRect (x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext (rect. size)
Let context = UIGraphicsGetCurrentContext ()
Context !. SetFillColor (color. cgColor)
Context !. Fill (rect)
Let image = UIGraphicsGetImageFromCurrentImageContext ()
UIGraphicsEndImageContext ();
Return image!
}
I have just been in contact with swift for a long time. If you have a better method, please don't hesitate to give me some advice. For reprinted information, please refer to the original address (it's okay if you don't attach it). ^_^)
Thank you!

Related Article

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.