首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iOS中使用componentKit设计视图

如何在iOS中使用componentKit设计视图
EN

Stack Overflow用户
提问于 2017-10-31 15:01:44
回答 1查看 249关注 0票数 0

我想在objective-c中使用componentKit创建一个自定义视图。该视图看起来像facebook应用程序中的新闻馈送视图,我编写了以下代码来创建该视图。

代码语言:javascript
复制
+ (instancetype)newWithText:(NSString *)text
                context:(QuoteContext *)context
          {

return [super newWithComponent:
        [QuoteWithBackgroundComponent
         newWithBackgroundImage:[context imageNamed:@""]
         quoteComponent:

         [CKInsetComponent
          newWithInsets:{.top = 10, .bottom = 10, .left = 10, .right = 10}
          component:
          [CKFlexboxComponent
           newWithView:{}
           size:{}
           style:{
               .direction = CKFlexboxDirectionVertical,
               //                 .spacing = 10,
           }
           children:{
               {
                   // Profile Picture
                   [CKImageComponent
                    newWithImage: nil
                    attributes:{
                        {@selector(setBackgroundColor:), [UIColor darkGrayColor]},
                        {CKComponentViewAttribute::LayerAttribute(@selector(setCornerRadius:)), 17.5}
                    }
                    size:CKComponentSize::fromCGSize(CGSizeMake(35, 35))],
               },
               {
                   // Name
                   [CKInsetComponent
                    newWithInsets:{ .right= 140, .top= -35}
                    component:
                    [CKLabelComponent
                     newWithLabelAttributes:{
                         .string = @"Asim Iftikhar Abbasi",
                         .font = [UIFont fontWithName:@"Baskerville" size:20],
                     }

                     viewAttributes:{
                         {@selector(setBackgroundColor:), [UIColor whiteColor]},
                         {@selector(setUserInteractionEnabled:), @NO},
                     }
                     size:{ }]],
                   .alignSelf = CKFlexboxAlignSelfEnd, // Right aligned
               },
               {
                   // Location
                   [CKInsetComponent
                    newWithInsets:{.right= 185, .top= -10}
                    component:
                    [CKLabelComponent
                     newWithLabelAttributes:{
                         .string = @"2 hrs Islamabad, Pakistan",
                         .font = [UIFont fontWithName:@"Baskerville" size:12]
                     }
                     viewAttributes:{
                         {@selector(setBackgroundColor:), [UIColor whiteColor]},
                         {@selector(setUserInteractionEnabled:), @NO},
                     }
                     size:{ }
                     ]],
                   .alignSelf = CKFlexboxAlignSelfEnd, // Right aligned
               },
               {
                   // Post
                   [CKInsetComponent
                    newWithInsets:{.right= 0, .top= 0}
                    component:
                    [CKImageComponent
                     newWithImage: nil
                     attributes:{{@selector(setBackgroundColor:), [UIColor blackColor]},
                     }
                     size:CKComponentSize::fromCGSize(CGSizeMake(400, 200))]],
                   .spacingBefore = 10
               },
               {
                   // Buttons
                   [CKInsetComponent
                    newWithInsets:{.right= 0, .top= 15}
                    component:
                    [CKButtonComponent
                     newWithAction:{}
                     options:{
                         .titles = @"Hello",
                         .attributes = {{@selector(setHighlighted:), @YES}},
                         .titleColors = titleColors,
                         .selected = YES,
                     }]],
                   .spacingBefore = 10
               },
           }]]]];
      }
     @end

我无法访问选项的属性

代码语言:javascript
复制
 options:{
                     .titles = @"Hello",
                     .attributes = {{@selector(setHighlighted:), @YES}},
                     .titleColors = titleColors,
                     .selected = YES,
                 }

当我访问buttontitles属性时,编译器生成以下错误:use of undeclared identifier titles

有谁能帮帮我..。提前感谢

EN

回答 1

Stack Overflow用户

发布于 2017-11-01 00:02:18

这里的ComponentKit expects from you不是单个字符串,而是UIControlState和字符串之间的映射,以便您可以为UIControlStateNormalHighlightedDisabled等定义不同的字符串。您可以指定为:

代码语言:javascript
复制
.titles = {{UIControlStateNormal, @"Hello"}}

但是,如果您不关心将默认has another constructor映射到normal状态的其他状态,则应按如下方式工作:

代码语言:javascript
复制
.titles = {@"Hello"}

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47029587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档