Q1. I have three controls:
-(void) doHorizontalFlowLayout:(NSArray *) viewArray
if(viewArray == nil || viewArray.count <=1
return; //get out of here, no need to continue
UIView *v0= (UIView *) [viewArray objectAtIndex:0]; // first view
CGRect frame0 = v0.frame;
CGFloat sumWidth= 0;
for(int i=1; i < viewArray.count; i++)
UIView *thisView= (UIView*) [viewArray objectAtIndex:i];
sumWidth = sumWidth+ v0.frame.size.width;
CGRect nextFrame= CGRectMake(frame0.origin.x
//the above works for 2 views only. For more than 2 views - reset v0 to point to the ith view
v0 = (UIView*) [viewArray objectAtIndex:i];
Was just struggling with this -- here is my solution:
There's no "flow layout" concept in iOS, so you have to calculate the widths of each control manually and place them absolutely in the parent container. UILabels are a bit different than buttons, as the only way to determine the content size is with the
[NSString sizeWithFont:...] method. See here for an example.
In your case, you'll have to listen for when user interaction is complete on whichever element is changing, and use the
[UIView setNeedsDisplay] (http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/setNeedsDisplay) method to redrawn the view and subviews.
This is much more difficult than it needs to be, IMHO.