ios - UIStackView inside UIScrollview -


i've added uiscrollview in added uistackview in storyboard. i'm trying add uistackview having 2 uilabels dynamically in parent uistackview although i'm giving height of child view ,it takes space of parent uistackview how solve or other way achieve this?

my code is

func createsummaryview() {     let labelsummary:uilabel = uilabel(frame: cgrectzero)     labelsummary.text = "summary"     labelsummary.heightanchor.constraintequaltoconstant(30).active = true       let summaryparentview:uistackview = uistackview(frame: cgrectzero)     summaryparentview.axis = .vertical     summaryparentview.alignment = .leading     summaryparentview.spacing = 1     let summaryviewwidth = width!-50     summaryparentview.heightanchor.constraintequaltoconstant(180).active = true     //summaryparentview.heightanchor.constraintequaltoanchor(summaryparentview.heightanchor, multiplier: 2).active = true     summaryparentview.addarrangedsubview(labelsummary)      _ in 1...5     {         let viewparent:uistackview = uistackview(frame: cgrectzero)         viewparent.axis = .horizontal         viewparent.widthanchor.constraintequaltoconstant(summaryviewwidth).active = true         viewparent.heightanchor.constraintequaltoconstant(30).active = true         viewparent.distribution = .fillequally          let labeltitle:uilabel = uilabel()         let labelvalue:uilabel = uilabel()         print("summary view width \(summaryviewwidth)")          labeltitle.text = "build"         labelvalue.text = "2012"         viewparent.addarrangedsubview(labeltitle)         viewparent.addarrangedsubview(labelvalue)          summaryparentview.addarrangedsubview(viewparent)         summaryparentview.translatesautoresizingmaskintoconstraints = false     }      stackviewvertical.layoutmarginsrelativearrangement = true     stackviewvertical.addarrangedsubview(summaryparentview)     stackviewvertical.translatesautoresizingmaskintoconstraints = false } 

where width width = stackviewvertical.frame.size.width

maybe library : https://github.com/gurhub/scrollablestackview

it's objective-c , swift compatible.

sample code (swift)

import scrollablestackview  var scrollable = scrollablestackview(frame: view.frame) view.addsubview(scrollable)  // add views  let rectangle = uiview(frame: cgrect(x: 0, y: 0, width: 100, height: 55)) rectangle.backgroundcolor = uicolor.blue scrollable.stackview.addarrangedsubview(rectangle) // ... 

sample code (objective-c)

@import scrollablestackview  scrollablestackview *scrollable = [[scrollablestackview alloc] initwithframe:self.view.frame]; scrollable.stackview.distribution = uistackviewdistributionfillproportionally; scrollable.stackview.alignment = uistackviewalignmentcenter; scrollable.stackview.axis = uilayoutconstraintaxisvertical; [self.view addsubview:scrollable];  uiview *rectangle = [[uiview alloc] initwithframe:cgrectmake(0, 0, 100, 55)]; [rectangle setbackgroundcolor:[uicolor bluecolor]];  // add views [scrollable.stackview addarrangedsubview:rectangle];  // ... 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -