首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ComponentsKit -在堆栈组件内右对齐项目

ComponentsKit -在堆栈组件内右对齐项目
EN

Stack Overflow用户
提问于 2015-04-05 14:07:15
回答 1查看 180关注 0票数 0

如何将2个项目添加到堆栈组件中,使堆栈延伸到其父组件的整个宽度,并将包含的项目锚定到堆栈容器中的相对边?

我发现的一种解决方案是添加一个宽度很大的空视图。这真的很糟糕。

代码语言:javascript
复制
#import "KPIComponent.h"
#import "CKImageComponent.h"
#import "CKStackLayoutComponent.h"
#import "CKLabelComponent.h"
#import "CKInsetComponent.h"

static UIImage *myImage;
@implementation KPIComponent

+(void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        myImage = [UIImage imageNamed:@"1"];
    });
}
+(instancetype)newWith {

    CKImageComponent * imageComponent = [CKImageComponent newWithImage: myImage];


    CKComponent * labelComponent = [self label];

    CKComponent *flexy = [self flex]; // add this as a separator 
    CKStackLayoutComponent *stack = [CKStackLayoutComponent newWithView:{
        [UIView class],
        {
            {@selector(setBackgroundColor:),[UIColor blueColor]}
        }
    }size:{
    }style:{
        .direction = CKStackLayoutDirectionHorizontal
    }children:{
        {
            .component = labelComponent,
        },
        {
            .component = flexy,
            .flexShrink = YES,
            .spacingBefore = 2,
            .spacingAfter = 2
        },
        {
            .component = imageComponent,
        }
    }];
    return [super newWithComponent:stack];


}

+(CKComponent *)label {
    CKLabelComponent *label = [CKLabelComponent newWithLabelAttributes:{
        .string = @"Some String",
        .font = [UIFont fontWithName:@"Baskerville" size:30],
        .color = [UIColor whiteColor],
        .maximumNumberOfLines = 0,
        .lineBreakMode = NSLineBreakByCharWrapping
    }viewAttributes:{
        {@selector(setBackgroundColor:), [UIColor clearColor]}
    }];
    return label;
//    CKInsetComponent *inset = [CKInsetComponent newWithInsets:{.top = 0, .left = 0, .bottom = 0, .right = 0} component:label];
//    return inset;

}

+(CKComponent *)flex {
    return [CKComponent newWithView:{
        [UIView class],
        {
            {@selector(setBackgroundColor:),[UIColor clearColor]}
        }
    }size:{10000,1}]; // a huge width so that if takes the full parent
}

@end
EN

回答 1

Stack Overflow用户

发布于 2015-05-07 11:52:21

您应该在stacklayoutComponent中设置左侧组件的.flexGrow = YES

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

https://stackoverflow.com/questions/29454632

复制
相关文章

相似问题

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