I have 3 images, a left cap, right cap, and center. Perhaps using CGImageRefs
(?), is there a way to build a bitmap based on a CGRect
that would center the center piece in some container, stretch the left cap until it reaches the center piece and the same for the right then produce a UIImage
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Your is a strange approach :)
You have three different images that compose a single stretchable image but you want to build it programmatically every time you have to use it in a certain way. This waste cpu cycles. iOS framework allow you to stretch an image as you would. Open your files into your image editor (Photoshop, or something similar). Compose a single image containing the center image surrounded by the left and right cap.
Now you can use this image as every other images or you can stretch it as you would using the UIImage method
The UIEdgeInsets is a simple struct that identify your cap limits. So supposing you have to stretch 15pt left and 20pt right you insets will be: top: 0 buttom:0 left:15 right:20
That's it.
Here for details. The article talk about a deprecated method from iOS 5.0 and above but the theory behind is the same.
I say just do it programatically, yes it might waste a few CPU cycles but it'll be more fun.
OK, here we go...
Let's have 3 UIImageViews defined in the header
In viewDidLoad we'll create them
then let's make a method you can use to set the position of the center image, and have the other images shimmy around into place, stretching themselves to the edges left and right.
Ok I looked it up as promised. Here is a solution:
The Basic Idea
UIImage
with stretched right sideUIImage
And here is a small graphic how i think it could word
The code
The alternative
Inspired by Jonathan Plaketts answers the same should ne possible with just
UIImageViews
and stretching the UIImages as above.