vendredi 30 janvier 2015

CSLinearLayoutView for iOS app not working as expected

I'm trying to use CSLinearLayoutView in an iPhone app, and I'm following the demo code to try and apply it. However, when I attempt to create a linear Layout of buttons (very basic just to test it) they all stack on top of each other instead of laying out how they should. what am I doing wrong? screenshot



- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// create the linear layout view
CSLinearLayoutView *linearLayoutView = [[CSLinearLayoutView alloc] initWithFrame:self.view.bounds];
linearLayoutView.orientation = CSLinearLayoutViewOrientationVertical;
[self.view addSubview:linearLayoutView];

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
label1.text = @"label1";

// create a layout item for the view you want to display
CSLinearLayoutItem *item = [CSLinearLayoutItem layoutItemForView:label1];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;

// add the layout item to the linear layout view
[linearLayoutView addItem:item];


UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
label1.text = @"label2";

// create a layout item for the view you want to display
CSLinearLayoutItem *item2 = [CSLinearLayoutItem layoutItemForView:label2];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;




UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
label1.text = @"label3";

// create a layout item for the view you want to display
CSLinearLayoutItem *item3 = [CSLinearLayoutItem layoutItemForView:label3];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;


UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
label1.text = @"label4";


// create a layout item for the view you want to display
CSLinearLayoutItem *item4 = [CSLinearLayoutItem layoutItemForView:label4];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;

CSLinearLayoutView *linearLayoutView2 = [[CSLinearLayoutView alloc] initWithFrame:self.view.bounds];
linearLayoutView.orientation = CSLinearLayoutViewOrientationHorizontal;

[linearLayoutView2 addItem:item2];
[linearLayoutView2 addItem:item3];
[linearLayoutView2 addItem:item4];




// create a layout item for the view you want to display
CSLinearLayoutItem *horizontal = [CSLinearLayoutItem layoutItemForView:linearLayoutView2];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;

[linearLayoutView addItem:horizontal];


}



Aucun commentaire:

Enregistrer un commentaire