0

Assume I have an image stored in Images.xcassets that is sliced; ie its capInsets property is set and I want to draw that image larger than its actual size in CoreGraphics. How do I do this?

Do I have to use the capInsets property to manually slice the image in to 9 parts and then grow/stretch the 9 parts manually or is there an easier way?

Quentin
  • 3,971
  • 2
  • 26
  • 29

1 Answers1

2
    UIGraphicsBeginImageContext(litView.layer.frame.size);
    [litImg drawInRect:litView.layer.frame];
    UIImage *resizedImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
JenVM
  • 36
  • 1
  • 2
    Please don't just have a block of code, add some explanation why it's correct. – ElectronicGeek May 02 '14 at 20:32
  • It would appear that @jenVM is suggesting that it will automatically draw correctly based on the cap insets. Before you accept the answer, you will probably want to check and make sure it works. – Zev Eisenberg May 02 '14 at 21:20
  • Also you must check for scale parameter: if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { UIGraphicsBeginImageContextWithOptions(litView.frame.size, NO, [[UIScreen mainScreen] scale]); } else { UIGraphicsBeginImageContext(litView.frame.size); } – arturdev May 05 '14 at 08:44