问题标签 [ibinspectable]

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 投票
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 投票
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.

0 投票
5 回答
29293 浏览

objective-c - 如何在 Objective-C 中为 IBInspectable 设置默认值?

我知道 IBInspectable-properties 的默认值可以设置为:

@IBInspectable var propertyName:propertyType = defaultValue在斯威夫特。但是如何在 Objective-C 中实现类似的效果,以便我可以将某些属性的默认值设置为 Interface Builder 中的某些内容?

0 投票
2 回答
1768 浏览

ios - 静态库、捆绑包和 IB Designable

我正在尝试在我的 UIButton 中使用 IB Designable 和 IB Inspectable,但似乎有一些错误。

在问题导航器中,捆绑文件:

情节提要: IB Designables:无法更新自动布局状态:无法从路径加载设计(空)

所以我想知道是否有任何配置可以在静态库或类似的东西中使用它?

这是

我想要实时渲染的自定义按钮位于视图控制器内

0 投票
3 回答
1279 浏览

ios - UIButton 上的 IBInspectable setTitle:forState 不起作用

我正在尝试使用 Interface Builder 中的实时渲染为 UIButtons 实现可本地化的类。这是我到目前为止的代码:

布局在 IB 中正确更新,但文本未显示。我用 UILabel 创建了相同的实现,它确实有效: https ://github.com/AvdLee/ALLocalizableLabel

欢迎任何有关如何解决此问题的想法!

0 投票
1 回答
1689 浏览

xcode - IB_DESIGNABLE 类未在 Interface Builder 上呈现

这是我第一次尝试在 Xcode 上使用 IB_DESIGNABLE。

我有这个类来为 NSView 添加颜色。

标题

执行

即使使用 IB_DESIGNABLE,此类也不会在界面生成器上以正确的颜色呈现...为什么?

0 投票
1 回答
100 浏览

ios - 我是否必须硬编码由 IBInspectable 属性调整的值?

如果我用于IBInspectable调整属性并在 Xcode 上获取实时更新,那么我是否必须对我选择的值进行硬编码,或者调整后的值是否会与最终版本一起编译?

我的意思是,假设我用来IBInspectable将视图的边框调整为 10。我应该将该边框硬编码为 10,还是将在 Interface Builder 上的框上调整的这个值是将为该边框编译的值?

有那么一会儿,中殿 IBInspectable 把我当作只是为了检查的东西......

0 投票
3 回答
11192 浏览

ios - 将 IBDesignable 和 prepareForInterfaceBuilder 与 UILabel 一起使用

我有一个正在创建的 call 子UIViewMyView

其中有一个UILabel(由于原因,这是在代码中而不是在 InterfaceBuilder 中添加的)。

MyView然后我有一个叫做的属性color

我想要的是让 Interface Builder 能够选择color并显示带有设置为该颜色的字体的标签。

在我的代码中,我...

IBInspectable

在 IB 中,我可以在那里看到颜色属性并且可以设置它。令人讨厌的是,它采用默认值 .clearColor() 虽然不是我在代码中设置的颜色。有没有办法解决这个问题?

IB可设计

当我将视图放入 InterfaceBuilder 时,它会显示所有可检查的属性,但实际视图中没有显示任何内容。

当我运行它时,一切正常。我只是希望能够在 IB 中得到一些工作(除了 drawRect)。不过,我发现明显缺乏文档。

编辑 - 警告

我刚刚注意到我收到构建错误/警告说......

警告:IB Designables:忽略“UIView”实例上关键路径“颜色”的用户定义运行时属性。尝试设置其值时遇到异常:[ setValue:forUndefinedKey:]:此类不符合键颜色的键值编码。

这可能会改变解决方案:)

0 投票
1 回答
1251 浏览

ios - IBInspectable 和协议

我正在使用名为“LiveRendering”的新 Xcode 6 功能。由于我需要在不同的自定义视图上大量使用一些可检查的属性,我想在协议中声明它们。

例如 :

  • LiveRenderingTextAttributesProtocol(声明 textColor、textSize 的可检查属性
  • LiveRenderingBorderAttributesProtocol(声明borderStyle、borderColor、borderWidth的可检查属性)

ETC ...

之后,每个自定义视图都实现了它需要的协议。

但是我在 InterfaceBuilder“属性检查器”列上看不到我的可检查属性:/当我将这些属性的值定义为“使用定义的运行时属性”时,LiveRendering 运行良好,但我想在我的属性检查器列中看到它们.

请问有解决这个问题的办法吗?

0 投票
1 回答
440 浏览

ios - 在 XIB 中使用多个 UITableView

我创建了一个自定义小部件作为一个XIB文件,其中有多个UITableViews 和一个UIButton. 在作为此 XIB 所有者的相应 swift 文件中,我有这些 TableView 的出口。

我已将此小部件添加到UIViewController. 现在在这个控制器的相应 swift 文件中,我需要为每个表视图分配dataSourcedelegate,并为按钮分配一个动作。

我在网上找了很久,似乎@IBInspectable vars 是要走的路,但似乎我无法制作 var which of typeUITableView或as 。UITableViewDelegateUITableViewDatasource@IBInspectable

那么如何使用表格视图和按钮呢?谁能指导我找到正确的文档、示例或解释?