Graphics Reference
In-Depth Information
rasterizationScale to match the screen to avoid views that look pixelated on a
Retina display.
As with UIViewGroupOpacity , use of the shouldRasterize property has
performance implications (which are explained in Chapter 12, “Tuning for Speed,” and
Chapter 15, “Layer Performance”), but the performance impact is localized.
Listing 4.7 Using shouldRasterize to Fix the Grouped Blending Problem
@interface ViewController ()
@property ( nonatomic , weak ) IBOutlet UIView *containerView;
@end
@implementation ViewController
- ( UIButton *)customButton
{
//create button
CGRect frame = CGRectMake ( 0 , 0 , 150 , 50 );
UIButton *button = [[ UIButton alloc ] initWithFrame :frame];
button. backgroundColor = [ UIColor whiteColor ];
button. layer . cornerRadius = 10 ;
//add label
frame = CGRectMake ( 20 , 10 , 110 , 30 );
UILabel *label = [[ UILabel alloc ] initWithFrame :frame];
label. text = @"Hello World" ;
label. textAlignment = NSTextAlignmentCenter ;
[button addSubview :label];
return button;
}
- ( void )viewDidLoad
{
[ super viewDidLoad ];
//create opaque button
UIButton *button1 = [ self customButton ];
button1. center = CGPointMake ( 50 , 150 );
[ self .containerView addSubview :button1];
//create translucent button
UIButton *button2 = [ self customButton ];
Search WWH ::




Custom Search