Graphics Reference
In-Depth Information
This means that we can resize our views arbitrarily and the border will remain consistent
(see Figure 2.10). This works in a similar way to the
-resizableImageWithCapInsets: method of UIImage , but can be applied to any
layer backing image, including one that is drawn at runtime using Core Graphics (as
covered later in this chapter).
Figure 2.10 A couple of views using the same stretchable backing image
Listing 2.4 shows the code for setting up these stretchable views programmatically.
However, an additional cool feature of contentsCenter is that it can be configured in
Interface Builder without writing any code at all by using the Stretching controls in the
Inspector window, as shown in Figure 2.11.
Listing 2.4 Setting Up Stretchable Views Using contentsCenter
@interface ViewController ()
@property ( nonatomic , weak ) IBOutlet UIView *button1;
@property ( nonatomic , weak ) IBOutlet UIView *button2;
@end
@implementation ViewController
- ( void )addStretchableImage:( UIImage *)image
withContentCenter:( CGRect )rect
Search WWH ::




Custom Search