2013-05-05 50 views
0

我收到此錯誤:試圖做的UIButton的子類未定義的符號 - 雖然做的UIButton子類

Undefined symbols for architecture i386: "_OBJC_CLASS_$_CAGradientLayer", referenced from: objc-class-ref in GradientButton.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

這是.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 

爲什麼?

+0

的[編譯錯誤嘗試使用CAGradientLayer(http://stackoverflow.com/questions/3902594/compile-error-trying-to-use-cagradientlayer) – Pfitz 2013-05-05 10:21:48

回答

3

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

看到這個:add framework to project

+0

你是可能重複對,你解決了我的問題。現在爲什麼我不能將這個按鈕作爲子視圖添加到另一個UIView? - (void)viewWillAppear:(BOOL)animated {super viewWillAppear:animated];我們可以通過下面的例子來說明如何使用這些顏色:[color = red] [color =#000000] [color =#000000] [self.view addSubview:button]; } 我得到Thread1 SIGBRT錯誤 – assafey 2013-05-05 11:24:00