Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton.layer.cornerRadius doesn't exist?

I'm implementing a custom UIButton with minimal functionality. The .h file:

#import <Foundation/Foundation.h>
@interface CustomButton : UIButton {
}
@end

I'm encountering a compilation error at line (A) in the .m file:

- (id)initWithCoder:(NSCoder *)coder {
    if(self = [super initWithCoder:coder]) {

        CALayer *layer = [self layer];
        NSLog(@"layer=%@",layer);
        NSLog(@"delegate=%@",[layer delegate]);

#ifdef __IPHONE_3_0
        layer.cornerRadius = 4.0f; // (A) error: request for member 'cornerRadius' in something not a structure or union
#endif
    }
    return self;
}

If I comment out line (A), I get the following output:

2009-10-08 17:35:06.681 MyApp[2596:4e07] layer=<CALayer: 0x3cdf520>
2009-10-08 17:35:06.683 MyApp[2596:4e07] delegate=<CustomButton: 0x3cdaff0; baseClass = UIButton; frame = (9 212; 255 55); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x3cdf520>>

According to the documentation, CALayer should have a cornerRadius property. I'm using iPhone SDK 3.1 and even added an #ifdef to confirm this.

Can someone please show me where I've overlooked the obvious?

Thanks

like image 584
tba Avatar asked Oct 09 '09 00:10

tba


2 Answers

Make sure you

#import <QuartzCore/QuartzCore.h>
into your header or implementation file.
like image 195
Ben Gottlieb Avatar answered Oct 30 '22 03:10

Ben Gottlieb


Try this,

 #import <QuartzCore/QuartzCore.h>

    Button.layer.cornerRadius = 15.0;
    [Button.layer setMasksToBounds:YES];
like image 22
Vineesh TP Avatar answered Oct 30 '22 05:10

Vineesh TP