私は UIImage をレンダリングし、UIImageを呼び出し- drawRect:
て渡されたものに配置しています。自動的にサイズが変更されて伸縮しますが、これは望ましくありません。元のサイズを維持するにはどうすればよいですか?CGRect
drawInRect: rect
UIImage* left = [UIImage imageNamed: @"Map_info_bubble_left"];
UIImage* center = [UIImage imageNamed: @"Map_info_bubble_center"];
UIImage* right = [UIImage imageNamed: @"Map_info_bubble_right"];
UIImage* leftCapStretched = [left resizableImageWithCapInsets: UIEdgeInsetsMake(0, 20, 0, 0)];
UIImage* rightCapStretched = [right resizableImageWithCapInsets: UIEdgeInsetsMake(0, 0, 0, 15)];
CGFloat fullWidth = leftCapStretched.size.width + center.size.width + rightCapStretched.size.width;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(fullWidth, center.size.height), NO, 0);
[leftCapStretched drawAtPoint: CGPointMake(0, 0)];
[center drawAtPoint: CGPointMake(leftCapStretched.size.width, 0)];
[rightCapStretched drawAtPoint: CGPointMake(left.size.width + center.size.width, 0)];
UIImage* callout = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[callout drawInRect: rect];
基本的に何が起こっているかというと、キャップが伸びている間、中央の画像は元のサイズのままであるはずですが、中央が伸びていて、キャップが十分に伸びていません。fullWidth
2 を掛けると、中心が本来あるべき姿に近づくことに気付きました。
編集:ドキュメントをもう少し読んだ後、より簡単に尋ねられます.UIImagedrawInRect:
が呼び出されたときに四角形に合わせてスケーリングするのを防ぐ方法はありますか?