【发布时间】:2026-01-09 22:05:01
【问题描述】:
我想在objective-c 中使用componentKit 创建一个自定义视图。该视图看起来像 facebook 应用程序中的新闻源视图,我编写了以下代码来制作该视图,
+ (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,
}
当我访问button 的titles 属性时,编译器会生成以下错误:
use of undeclared identifier titles
请任何人帮助我...在此先感谢
【问题讨论】:
-
能否添加产生错误的代码部分?
-
[CKInsetComponent newWithInsets:{.right= 0, .top= 15} 组件:[CKButtonComponent newWithAction:{} 选项:{ .titles = @"Hello", .attributes = {{@selector( setHighlighted:), @YES}}, .titleColors = titleColors, .selected = YES, }]] 在这我无法获得选项属性
-
好吧,我猜是类型不对。试试
.titles = {{UIControlStateNormal, @"Hello"}}。
标签: ios objective-c objective-c++ componentkit