问题标签 [ibdesignable]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
6 回答
10425 浏览

ios - 添加到测试目标时的 IBDesignable 错误

我有一个用varUIButton实现的简单子类:IBDesignableIBInspectable

我没有在框架中使用它,它在 Interface Builder 中按预期工作,但是,一旦我将此子类添加到我的Tests目标,它就会停止实时渲染,并且我收到以下错误:

如果我删除IBDesignableIBInspectable变量,错误就会消失——不幸的是,Interface Builder 中的实时渲染也是如此。

如何在IBDesignable没有这些错误的情况下针对类进行测试?

0 投票
3 回答
3618 浏览

ios - Live Xcode 的 Interface Builder UIView 子类 (IB_DESIGNABLE) 没有 drawRect:

是否可以创建一个UIView在 Xcode 中实时呈现的子类(通过添加此处IB_DESIGNABLE解释的属性)但没有自定义方法?drawRect:

我们有一个自定义UIView子类,它使用一些CAShapeLayer添加到self.layer绘图的 s (因此,不需要覆盖drawRect:)。此类在 App 上运行良好,但不会在 Xcode 上呈现。

如果我们复制其中的代码,drawRect:它可以工作,但我们更愿意让绘图在图层上自动发生。

这可以做到吗?


我也试过做

这似乎适用于设备但不适用于 Xcode 的 IB。

0 投票
3 回答
4572 浏览

ios - 使用来自 pod 依赖项的 IB_DESIGNABLE 实时渲染自定义组件

IB_DESIGNABLE在吊舱中使用时遇到了一些困难。

我创建了一个自定义视图,我将其标记为IB_DESIGNABLE并制作了一个使用它的示例项目。到目前为止没有问题。

将该自定义视图添加为 pod 依赖项时会出现此问题。虽然项目构建并运行成功,但是在打开使用自定义视图的storyboard时出现错误。实时渲染过程开始并尝试在界面构建器中实时显示视图,但失败并出现以下错误:

在此处输入图像描述

这太糟糕了,因为我们失去了实时渲染,在我看来,这是 Xcode 6 中最好的功能之一。

  • Cocoapods gem 版本:0.34.4
  • Xcode 版本:6.1 (6A1052d)

我已经尝试过其他使用IB_DESIGNABLE并具有podspec

  1. https://github.com/Eddpt/EAColourfulProgressView(类EAColourfulProgressView:)
  2. https://github.com/hayashi311/HRButton(类HRButton:)
  3. https://github.com/Estimote/iOS-Indoor-SDK(类ESTIndoorLocationView:)

其他人在Estimote - Indoor Location Error中遇到了同样的问题,但所描述的解决方案意味着失去实时渲染功能。

有没有人能够IB_DESIGNABLE通过 Cocoapods 使用组件?

错误:“无法从路径(空)加载可指定项”

0 投票
2 回答
2231 浏览

ios - 为什么我的 IBDesignable 不允许我在自定义 UIButton 上使用 setImage:?

layoutSubviews我调用setImage()并传递它时UIImage,它从未出现在 Interface Builder 中,但它总是在我运行程序时出现。

0 投票
2 回答
9051 浏览

xcode - IBDesignable UIButton 子类

我正在尝试实现一个简单的 IBDesignable UIButton 子类。我希望能够从 Interface Builder 为控件的每个状态设置颜色。我知道这可以通过 IBInspectable 关键字来实现。在 state 属性上使用 KVO 时,我遇到了 IB 崩溃的问题。IBDesignable 调试器在 deinit 上崩溃。有谁知道我如何与 KVO 和 IBDesignable 一起工作?

0 投票
11 回答
46429 浏览

ios - IB_DESIGNABLE, IBInspectable -- Interface builder does not update

I have the following set of code:

CustomView.h

CustomView.m


(For Swift reference, this problem was also occurring with Swift code)

CustomView.swift


I added a UIView to a view controller on the storyboard and set its subclass to CustomView.

enter image description here

This adds the "Designables" row. It is stuck on "Updating" and the tooltip says "Waiting for Target to Build". It never changes from this status.

When I move to the attributes inspect, I am able to set these IBInspectable properties:

enter image description here

And once set, they also show up in the "User Defined Runtime Attributes":

enter image description here

However, the "Designables" status never moves beyond "Updating" with still the same tooltip (I've tried Cmd+B building several times, nothing changes).

Moreover, as I set the IBInspectable properties, I get a warning for each one:

IBDesignables - Ignoring user defined runtime attribute for key path "borderColor" on instance of "UIView" ... this class is not key-value coding-compliant for the key borderColor.

Screenshot of the warnings generated:

enter image description here


I am familiar with the key-value coding-compliant issues and generally know how to solve them... but I don't understand how to solve this issue here. According to the view's identity inspector, the view is a "CustomView" (not a regular "UIView", which doesn't have these properties). And if the view weren't a "CustomView" then these designable properties wouldn't show up in the Attributes Inspector, right? But when Interface Builder tries to apply these attributes to the view, it goes back to thinking the view's class is "UIView" and cannot apply the attributes.

Any help? Please let me know if I've left out some important detail, but for what it's worth, I followed this tutorial exactly (other than ObjC vs Swift). It's also worth noting that I followed this tutorial exactly on another machine and it worked like a charm (I intended to make this post last night but the computer I was on then didn't have this issue).


Based on comments, it has been suggest that perhaps the .m file isn't included and that might be causing the problem. I thought surely I would have gone out of my way for this scenario to be the case, but I checked anyway.

enter image description here

When I first started attempting to do this, I was under the understanding that the IB_DESIGNABLE classes had to be part of a different UIKit framework. So from this first screenshot, you can see that I set up a "CustomViews" framework, which has one class, CustomView. You'll also see here that I also created a OtherView, which is identical to CustomView, except it's not in a separate framework. The identical problem persists on the storyboard between both classes however.

Here we have a screenshot indicating that CustomView.m is included to be built with the CustomViews framework:

enter image description here

Meanwhile, the following screenshot indicates several things:

  • CustomViews.framework is appropriately included in the main project.
  • OtherView.m is also included as a compile source, so even if something is wrong with CustomView, OtherView should work, however it generates identical errors.
  • Main.storyboard and LaunchScreen.xib are showing up as red. I have no idea why, and haven't the slightest clue as to why LaunchScreen.xib should (I haven't touched this file), though I can say after looking at other projects, Main.storyboard also shows up in red for those projects, and I'm not doing anything with IB_DESIGNABLE or IBInspectable there.

enter image description here


I have tried and retried this several times now. It works every time on my computer at home--I can not reproduce the problem described in this question at home. At work, it never works. The problem described in this question happens every time.

Both computers are Mac Minis purchased new this year (not the new models, late 2012 model). Both computers are running OS X Yosemite 10.10. Both computers are running Xcode Version 6.1. At home, the build is (6A1052d). This morning, I can confirm that both computers are running identical builds of Xcode.

Others have suggested to me that it might be bad RAM. That seems far fetched to me. I've restarted the project multiple times, restarted the computer multiple times. Seems to me if there were bad RAM on a computer approximately 6 months old, that I'd be seeing other problems, and that this problem would be less consistent. But this exact problem persists despite numerous times restarting the entire project from scratch and full restarts on the computer.


It should be worth noting that if I actually compile and run this project, the custom view with the IBInspectable properties actually displays as I expect the storyboard to display it. I imagine that this would be the case even with out the IB_DESIGNABLE and IBInspectable directives however, as these are created as User Defined Runtime Attributes.

0 投票
3 回答
13384 浏览

swift - IBInspectable 创建下拉菜单和更好的组织

简而言之,我想创建一个@IBInspectable属性,当您在 Storyboards 中时,该属性允许您从下拉菜单中的列表中进行选择。此外,如果有一种方法可以创建分隔线并更好地组织,IBInspectables我想知道这是否也是可能的。在我的示例中,我想为电话号码创建正则表达式字符串,这样当我转到情节提要时,我可以在下拉菜单中选择“电话号码”项,而不是输入正则表达式字符串。

目前我已经对 a 进行了子类化,TextField以便我可以向它添加更多IBInspectables内容,例如正则表达式(您可以在图片中看到)。所以就目前而言,这就是我的子类UITextField

正则表达式工具栏

0 投票
5 回答
10025 浏览

ios - IBDesignable 视图渲染超时

从第一个 XCode 6/iOS 8 beta 版本开始,我一直在断断续续地开发一个应用程序几个月。我最喜欢添加的功能之一是实时渲染,这可以通过@IBDesignableSwift 中的标签实现。

我还没有得到任何东西来实时渲染。我想这一定是因为它是一个测试版,所以我决定等待完整版本出来再试一次。它仍然失败。我当时认为我的代码中可能存在来自 beta 版本的工件,所以我放弃了它并重新开始。它仍然不起作用。当然,这些错误现在更具描述性。

这是我的代码:

以下是我尝试在情节提要中使用这些按钮之一进行构建时遇到的错误:

正如您在我的代码中看到的那样,我最初希望这个按钮是圆形的。我想这可能是这个问题的原因,尽管令我惊讶的是,Apple 会设计一个低效的圆角矩形绘图算法。我切换到简单地设置颜色并按原样绘制矩形。还是有问题。

我认为(无论如何我希望)我做错了一件小事,因为我已经用谷歌搜索了,似乎没有其他人有这个问题。似乎它可能是某种无限循环?

这不是我必须继续做的事情,但是让实时渲染工作将使开发对我来说更快、更容易,因为我将能够看到我的接口并对其进行测试,而无需运行它们。

提前感谢任何对如何解决这个问题有远程线索的人。

0 投票
1 回答
2044 浏览

swift - 快速 IBDesignable 视图未显示在情节提要中

我想自定义一个 5 星 UIView,也希望它在故事板中呈现。所以我决定使用@IBDesignable 和@IBInspectable。以下是我的代码。

然后在我的故事板中,我将一个 UIView 拉到我的画布中,并将自定义类设置为我的自定义视图作为 RatingView。编译器开始编译故事板文件,我只是等待自定义视图在画布中呈现。这是屏幕截图. 在此处输入图像描述

状态是“最新的”,但视图尚未渲染。视图只是保持白色,我想看到的是我添加到父视图的图像。当我使用 UILabel 而不是 UIImageView 时,标签在画布中呈现,而不是 UIImageView,我怎样才能在画布中呈现我可爱的星星图像。(Images.xcassets 有 star.png 文件)

在此处输入图像描述

使用 UILabel 代替 UIImageView

结果: 在此处输入图像描述

0 投票
1 回答
505 浏览

ios - Xcode 6 @IBInspectable: Initialize to starting value?

When you add @IBInspectable properties, they are initialized to essentially... nothing.

enter image description here

Is there a way to have these properties default to something? Say a red color for the track color, grey color for the background color and 10.0 for padding? I've tried @IBInspectable public var padding: CGFloat = 10.0 but the "10" does not get reflected in IB.