0

I've been doing a lot of reading as a new Swift programmer and learned that Stack Views are the way to go to dynamically position elements rather than relying on auto-layout. What I've been trying to do is set a stack view/frame where I can dynamically position drawn circles with in it.

Suppose I input a value of 5, 5 circles will be drawn and automatically spaced & positioned within the frame. Likewise, an input of 3 will draw 3 circles and dynamically position them.

I've started with an array just for testing purposes:

// Function to Draw the Circle
func colorCircle(withColor color:UIColor, title:String) -> UIBezierPath{
    let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, 300, 300))
        UIColor.whiteColor().setFill()
        ovalPath.fill()

    return ovalPath
}

// Dictionary Collection of colors (Basically an end result of 3 circles with these colors)
var colorDictionary = [
    "Red":UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0),
    "Green":UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0),
    "Blue":UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0),
]

// My Array of Circles
var circleArray = [UIBezierPath]()

// Add X Amount of Circles (colors) in Array in Regard to the Amount of Colors in the colorDictionary collection
for (myKey,myValue) in colorDictionary{
    circleArray += [colorCircle(withColor: myValue, title: myKey)]
}

It's been hours and I'm starting to lose hope. I'm just trying to get my feet wet with appending circles in this stack view so I get into more serious implementations.

Much help would be appreciated!

theflarenet
  • 642
  • 2
  • 13
  • 27
  • 2
    Sounds like you should be adding UIViews to your stackview, not UIBezierPaths. – AJ9 Mar 17 '16 at 16:21
  • Ahhhhh! You're right. A silly mistake in constructing this quick prototype in order to elaborate this. I'll give it another shot. – theflarenet Mar 17 '16 at 16:46

0 Answers0