iphone - 架构 i386 的 undefined symbol - 在制作 UIButton 子类时

标签 iphone ios xcode uibutton subclass

我收到这个错误:

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)

尝试创建 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

为什么???

最佳答案

你有没有在你的项目中加入QuartzCore框架?

看这个:add framework to project

关于iphone - 架构 i386 的 undefined symbol - 在制作 UIButton 子类时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16383437/

相关文章:

c# - 需要我已经拥有的 Objective-C 版本的 Java 加密和 Base 64 编码

iphone - 当用户单击一行时,如何移动到另一个 View Controller ?

iphone - UIView 调整大小和平移动画不能正确地为 subview 设置动画

iOS 通用链接在某些设备上不起作用

ios - Objective-C 中的 cURL 请求 (POST)

iOS:在 numberOfRowsInSection 中返回 2 个计数值

objective-c - 核心数据中的关系同步

iphone - 将 iPhone 设备连接到外部设备

ios - 与关联值匹配的 Swift 枚举模式 - 无法调用函数

ios - Xcode 7 的签名身份对话框窗口中的重置按钮如何工作