0

我想使用componentKitin创建自定义视图objective-c。该视图看起来像facebookapp 中的新闻提要视图,我编写了以下代码来制作该视图,

+ (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

我无法访问选项的属性

 options:{
                     .titles = @"Hello",
                     .attributes = {{@selector(setHighlighted:), @YES}},
                     .titleColors = titleColors,
                     .selected = YES,
                 }

当我访问编译器的titles属性时会button产生以下错误: use of undeclared identifier titles

任何人都请帮助我...在此先感谢

4

1 回答 1

0

ComponentKit对您的期望不是单个字符串,而是UIControlStates 和字符串之间的映射,以便您可以为UIControlStateNormalHighlighted等定义不同的字符串Disabled。您可以指定为:

.titles = {{UIControlStateNormal, @"Hello"}}

但是,如果您不关心其他状态,则 map有另一个默认为正常状态的构造函数,其工作方式如下:

.titles = {@"Hello"}

希望有帮助!

于 2017-10-31T16:02:18.330 回答