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
Make sure you
#import <QuartzCore/QuartzCore.h>into your header or implementation file.
Try this,
#import <QuartzCore/QuartzCore.h>
Button.layer.cornerRadius = 15.0;
[Button.layer setMasksToBounds:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With