ios - 将 UIFont 对象从 React-Native 传递给 Swift
问题描述
我有一个由 React-Native 视图管理的原生 Swift 组件。从我的 RN 视图中,我想传递一个 UIFont 对象,该对象应该可以在 Swift 中使用。通过以下实现,swift 中的属性被调用,但不会从 RN 视图中获取值。
<NativeSwiftView
uiFontStyle={{ name: "Arial", size: 15 }}
/>
该属性由目标 c 公开,如下所示:
@interface RCT_EXTERN_MODULE(RCTNativeSwiftViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(uiFontStyle, UIFont)
@end
在 Swift 中,该属性如下所示:
@objc var uiFontStyle = UIFont(name: "", size: 0) {
didSet {
print("Did set: ", uiFontStyle!)
self.font = uiFontStyle!
}
}
在 didSet 运行后,这将打印到控制台:
Did set: <UICTFont: 0x7fef00c2b2b0> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 14.00pt
为什么 print 语句的值不是我在 RN 视图中设置的值?
解决方案
推荐阅读
- apache-camel - 通过注解引用 Karaf 上的声明式服务
- java - 从 Logstash 输出到事件中心很慢
- python - 使用 xcopy 静默复制文件 - Python Windows 10
- forms - 在没有实际单击按钮的情况下调用 C# click 事件不起作用
- azure - COSMOS DB 触发 Azure Function changefeed 错误
- go - 其他包上的 GORM DB 连接
- python - 找不到 SQLAlchemy 错误表
- c# - 从 Google 云端硬盘中排除一个文件夹
- google-chrome-extension - Rx.js,Chrome 消息传递 API
- javascript - 这是使用 componentDidMount 的有效方法吗?