あなたの画像がランダムな形で透明である場合(つまり、画像の輪郭がハローキティの形である場合)、私はこれにアプローチします...
まず、ここでは UIImageView を無視します。カスタム UIView サブクラスを作成する方が簡単かもしれません。
ビューの drawRect で...
- (void)drawRect:(CGRect)rect
{
// calculate the rect of the image (aspect ratio etc...) so that it fits in the rect.
// see this link https://stackoverflow.com/questions/7645454/resize-uiimage-by-keeping-aspect-ratio-and-width
// change the colour of the image to black (or the border colour you want).
// see this link http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage
// draw the black image in the rect you calculated
// make a new rect that is smaller by in x and y than the one for the black image.
// You can change it by different amounts to change the border size
// draw the colour image in the new rect
}
各ステップにはかなりのコードが必要なので、リンクと提案のみを掲載しましたが、これは、あなたがしていることをやろうとしている場合に行うことです.
リンク 1 -アスペクト比と幅を維持して UIImage のサイズを変更する
リンク 2 - http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage