【问题标题】:why can this code not access 'borderWidth' (iphone code attached)为什么这段代码不能访问'borderWidth'(附上iphone代码)
【发布时间】:2011-07-16 10:29:24
【问题描述】:

为什么这段代码不能访问'borderWidth'(附上iphone代码)

这是基于一个简单的测试项目,但我确实添加了 QuartzCore 框架,但这并没有帮助。仍然抛出错误,请参见下面的代码。我这样做的另一个项目工作正常,我看不出有什么区别

#import "Customview.h"
@implementation Customview
- (id)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {

        // UI Layout
        self.layer.borderWidth = 5; // ERROR error: accessing unknown 'borderWidth' component of a property
    }
    return self;
}

【问题讨论】:

    标签: iphone ios uiview xcode4 calayer


    【解决方案1】:

    您需要添加 QuartzCore 框架才能访问任何 UIView 的 layer 属性。你添加了吗?

    如果您使用的是 xCode 4,请按照以下步骤添加框架

    1. Select Target
    2. Build Phases
    3. Link Binary with Library Section
    4. Tap + and find for the Quartz
    5. Add Framework. 
    

    现在,将它导入到您想要访问任何 UIControl 的图层属性的任何位置。

    #import <QuartzCore/QuartzCore.h>
    

    希望对您有所帮助。

    【讨论】:

    • 另外你需要import
    • 是的,我确实这样做了(但没有帮助?) - 转到 Target => Build Phases => Link Binary with Libraries => 添加了 QuartzCore.framework。我还有什么需要做的吗?您不必有任何特殊的“导入”行吗?
    • 是的,格雷格,你需要写导入声明我编辑了我的答案检查。
    猜你喜欢
    • 2018-09-23
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 2019-10-27
    • 2021-05-05
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多