将3个不同的UI组件重构为一个UIView并转换为CocoaPod [英] Refactoring 3 different UI components into one UIView into a CocoaPod

查看:59
本文介绍了将3个不同的UI组件重构为一个UIView并转换为CocoaPod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS项目中,我一直在重复使用相同的3种不同类型的UI元素:

in my iOS project i've been re-using the same 3 different types of UI elements:


  • 标签

  • 输入

  • 复选标记(或X)。

和逻辑相同:


  • 当用户输入文本时,请进行验证。

  • 验证失败,红色复选标记等时。

因此,下一个显而易见的阶段是将其重构为一个UIView,以便进行拖放。

So, the next obvious stage is to refactor this into one UIView so that I can just drag and drop.

我希望将其放入可可豆荚中。

And I want this into a Cocoa pod.

将元素重构到UIview中并不难。但是我一直坚持将这种逻辑放入可可豆荚中。 XIB未加载,因此子视图为空。

Refactoring the elements into a UIview, etc is not hard. But I'm stuck on putting this logic into a Cocoa Pod. The XIB doesn't load so the subview is empty.

我已将 IB_DESIGNABLE 添加到头文件中,但仍然没有呈现。还有运行时的异常。

I've added IB_DESIGNABLE to the header file but still no rendering. And exception at runtime.

建议?我可以提供什么帮助?

Suggestions? What can I post to help?

编辑:

我的podspec资源部分

My resource section of the podspec


s.source_files = 'Pod/Classes/**/*'
  s.resources = 'Pod/Assets/**/*'
  s.resource_bundles = {
    'jawbreaker' => ['Pod/Assets/*.png']
  }


推荐答案

UIView不会自动加载XIB文件。创建UIView类时,您需要以下内容: http://eppz.eu / blog / uiview-from-xib-simplest /

UIView doesnt load XIB file automatically. When you create an UIView class you need something like this: http://eppz.eu/blog/uiview-from-xib-simplest/ .

MyView *view = [Myview loadFromNib];

如果要使用IB_DESIGNABLE,请记住: https://stackoverflow.com/a/26202160/846780

An if you want use IB_DESIGNABLE remember: https://stackoverflow.com/a/26202160/846780

这篇关于将3个不同的UI组件重构为一个UIView并转换为CocoaPod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆