架构i386的未定义符号 - 在制作UIButton子类时

时间:2013-05-05 10:09:06

标签: iphone ios xcode uibutton subclass

我收到此错误:

  

架构i386的未定义符号:         “_OBJC_CLASS _ $ _ CAGradientLayer”,引自:             GradientButton.o中的objc-class-ref       ld:找不到架构i386的符号       clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

在尝试创建UIButton的子类时:

这是h文件:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface GradientButton : UIButton

@property (assign, nonatomic) int borderWidth;
@property (assign, nonatomic) UIColor *buttonColor;
@property (strong, nonatomic) UIColor *borderColor;
@property (strong, nonatomic) NSString *title;

- (id)initWithFrame:(CGRect)frame botderWidth:(int)width borderColor:(UIColor *)bColor buttonColor:(UIColor *)btnColor title:(NSString *)btnTitle;


@end

这是m文件:

#import "GradientButton.h"

@interface GradientButton (Private)

- (void)initBorder;
- (void)initCorners;
- (void)initColorsAndFont;
- (void)initStyle;
- (void)initGradient;

@end

@implementation GradientButton
@synthesize borderColor, borderWidth, title, buttonColor;

- (id)initWithFrame:(CGRect)frame botderWidth:(int)width borderColor:(UIColor *)bColor buttonColor:(UIColor *)btnColor title:(NSString *)btnTitle
{
    borderWidth = width;
    borderColor = bColor;
    title = btnTitle;
    buttonColor = btnColor;    

    [self initBorder];
    [self initCorners];
    [self initColorsAndFont];
    [self initStyle];
    [self initGradient];

    return self;
}

- (void)initBorder {
    self.layer.borderWidth = borderWidth;
    self.layer.borderColor = borderColor.CGColor;
}

- (void)initCorners {
    self.layer.cornerRadius = self.frame.size.height / 2.0f;
}

- (void)initColorsAndFont {
    self.backgroundColor = buttonColor;
    [self setTitle:title forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}

- (void)initStyle {
    self.layer.shadowColor = [UIColor darkGrayColor].CGColor;
    self.layer.shadowOpacity = 1.0;
    self.layer.shadowOffset = CGSizeMake(2.0, 2.0);
}

- (void)initGradient {
    CAGradientLayer *layer = [CAGradientLayer layer];
    NSArray *colors = [NSArray arrayWithObjects:
                       (id)[UIColor whiteColor].CGColor,
                       (id)buttonColor,
                       nil];
    [layer setColors:colors];
    [layer setFrame:self.bounds];
    [self.layer insertSublayer:layer atIndex:0];
    [self setClipsToBounds:YES]; 
}


@end

为什么???

1 个答案:

答案 0 :(得分:3)

您是否在项目中添加了QuartzCore框架?

请参阅:add framework to project