Core Graphics Vs Images for a custom button
When should I go with core graphics over images for making a custom UIButton?
Is core graphics faster? Other than resolution independence, are there any other major benefits?
2 Solutions Collect From Internet About “Core Graphics Vs Images for a custom button”
Pros of Core Graphics:
- Code for drawing a button will probably be smaller than an image file.
- Allows dynamic modification, slight changes without adding a complete second image.
- As you mentioned, resolution independent.
- Less memory intensive (doesn’t allocate memory to hold every pixel).
Pros of images:
- Creating the image in an editor will usually be simpler than writing code which draws it perfectly. (If you use anything other than solid colors, it could be much simpler.)
- The editor will let you see the image beforehand without recompiling.
- Easier to work with other built in objects (i.e., you can make it the background of a UIButton).
As for running time, I am not sure. I would guess that CG would be faster for simple drawing, where most of the pixels aren’t changed, but images would be faster for more complex drawing where most of the pixels are changed (Assuming you use the PNG format, so it gets optomized. Otherwise, CG would probably always be faster).
As a compromise, you could draw into an image once, and use that image for future drawing. This would allow you to get some of the benefits from each.
Additional thoughts to ughoavgfhw’s comment:
Images can be cached (like when you use
[UIImage imageNamed:]). So you even won’t use more memory for new buttons, except the first one displayed. (And no allocations, except memory for a new pointer).
You can use stretchable images for button creation, and avoid some (not all and not always) problems with resolution dependence:
UIImage *myImg = [UIImage imageNamed:@"myImg.png"]; UIImage *myImgStretchable = [myImg stretchableImageWithLeftCapWidth:10 topCapHeight:10]; [myButton setBackgroundImage:myImgStretchable forState:UIControlStateNormal];
- Done button event MPMoviePlayerController
- How to enable testability for Framework in Release mode?
- How to reload tableview from another view controller in swift
- How to test Apple Push Notifications Feedback Service?
- forge.facebook.ui callback invoked with null on iOS
- Unable to dismiss MFMailComposeViewController, delegate not called
- How to display an activity indicator with text on iOS 8 with Swift?
- UISearchController search bar overlap first cell when active
- contentView not indenting in iOS 6 UITableViewCell prototype cell
- What files in an Xcode iOS project should I tell Mercurial to ignore?
- Can swift closures be set to a default value when used as a parameter in a function?
- write into plist file using NSDictionary object
- didFailToRegisterForRemoteNotificationsWithError: user refused error?
- Xcode App Running Issue
- Conditional segue performed on tap on UITableViewCell