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!