简体   繁体   English

UIButton.layer.cornerRadius不存在?

[英]UIButton.layer.cornerRadius doesn't exist?

I'm implementing a custom UIButton with minimal functionality. 我正在实现一个具有最小功能的自定义UIButton。 The .h file: .h文件:

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

I'm encountering a compilation error at line (A) in the .m file: 我在.m文件中的第(A)行遇到编译错误:

- (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: 如果我注释掉(A)行,我得到以下输出:

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. 根据文档 ,CALayer应该有一个cornerRadius属性。 I'm using iPhone SDK 3.1 and even added an #ifdef to confirm this. 我正在使用iPhone SDK 3.1,甚至添加了#ifdef来确认这一点。

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM