Open svaz opened 11 years ago
The way to do this in storyboard should be the same as using it regularly.
Drap and drop a generic view onto the storyboard. Then set a custom class for that generic view
is there any way to use it using storyboard?
Cool control but not sure how to get it working in a storyboard. You can not just drop a view onto the storyboard unless it is in a view controller. Wondering if there is a way to get it to work using a container view. http://stackoverflow.com/questions/11386111/uiview-outside-of-a-view-controller-in-a-storyboard
I used this approach: You don't drop the view into the storyboard but add the UIView to the list of components for the specific ViewController. Please see the attached screenshots.
And the ViewController.m:
// // ViewController.m // CollapseClick // // Created by Ben Gordon on 2/28/13. // Copyright (c) 2013 Ben Gordon. All rights reserved. //
@interface ViewController ()
@end
@implementation ViewController
@synthesize itemArray; @synthesize item; @synthesize category; @synthesize date1; @synthesize date2; @synthesize serial;
(void)viewDidLoad { [super viewDidLoad]; item.text = @"try this"; category.text = @"Home"; date1.text = @"todays date"; date2.text = @"another date"; serial.text = @"serial no";
itemArray = [[NSMutableArray alloc] initWithObjects:item,category, date1, date2,serial, nil];
NSLog(@"itemArray: %@", itemArray);
myCollapseClick.CollapseClickDelegate = self; [myCollapseClick reloadCollapseClick];
// If you want a cell open on load, run this method: //[myCollapseClick openCollapseClickCellAtIndex:1 animated:NO];
/* // If you'd like multiple cells open on load, create an NSArray of NSNumbers // with each NSNumber corresponding to the index you'd like to open. // - This will open Cells at indexes 0,2 automatically
NSArray indexArray = @[[NSNumber numberWithInt:0],[NSNumber numberWithInt:2]]; [myCollapseClick openCollapseClickCellsWithIndexes:indexArray animated:NO]; / }
// Required Methods -(long)numberOfCellsForCollapseClick { return 5; }
-(NSString *)titleForCollapseClickAtIndex:(long)index { NSLog(@"%s", FUNCTION); switch (index) { case 0: return @"Item Information"; break; case 1: return @"User Information"; break; case 2: return @"Company Information"; break;
case 3:
return @"Images";
break;
case 4:
return @"Notes";
break;
default:
return @"";
break;
}
}
-(UIView *)viewForCollapseClickContentViewAtIndex:(long)index { // NSLog(@"%s", FUNCTION); switch (index) {
case 0:
return itemView;
break;
case 1:
return test2View;
break;
case 2:
return test3View;
break;
case 3:
return nil;
break;
case 4:
return notesView;
break;
default:
return test3View;
break;
}
}
-(void) jumpToImages { NSLog(@"images....."); }
// Optional Methods
-(UIColor *)colorForCollapseClickTitleViewAtIndex:(long)index { return [UIColor colorWithRed:223/255.0f green:47/255.0f blue:51/255.0f alpha:1.0]; }
-(UIColor *)colorForTitleLabelAtIndex:(long)index { return [UIColor colorWithWhite:1.0 alpha:0.85]; }
-(UIColor *)colorForTitleArrowAtIndex:(long)index { return [UIColor colorWithWhite:0.0 alpha:0.25]; }
-(void)didClickCollapseClickCellAtIndex:(long)index isNowOpen:(BOOL)open { NSLog(@"%ld and it's open:%@", index, (open ? @"YES" : @"NO")); if (index == 3) [self jumpToImages]; }
-(void)textFieldDidBeginEditing:(UITextField *)textField{ //NSLog(@"%s", FUNCTION);
[textField setReturnKeyType:UIReturnKeyDone];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
/* //This activates any buttons with a view - like make larger in the original // Example of change content view frame and then update collapseClick layout.
(IBAction)buttonClicked:(id)sender { NSLog(@"button clicked");
itemView.frame = CGRectMake(0, 0, itemView.frame.size.width, itemView.frame.size.height + 50); [myCollapseClick setNeedsLayout]; } */
@end
@david…thanks for the answer. Did not realize I could just drop a uiview into the list of components. . I tried it and sure enough it works but now I have no way of actually seeing the view in IB to lay it out. I can drag and drop controls in the list but can not actually see the view. Not much different than creating the views programatically.
I did keep the collapseCell as an external nib. So, no more code than before.
On Apr 27, 2014, at 5:45 AM, Pete Chmiel notifications@github.com wrote:
@david…thanks for the answer. Did not realize I could just drop a uiview into the list of components. . I tried it and sure enough it works but now I have no way of actually seeing the view in IB to lay it out. I can drag and drop controls in the list but can not actually see the view. Not much different than creating the views programatically.
— Reply to this email directly or view it on GitHub.
But how did you layout the controls on the different UIViews? If you can not see the view in a storyboard then I might as well just use the xib or create the view programmatically. right?
I made nibs of each cell section. These are linked to the storyboard either through name identifiers or tags On Apr 27, 2014, at 5:53 AM, Pete Chmiel notifications@github.com wrote:
But how did you layout the controls on the different UIViews?
— Reply to this email directly or view it on GitHub.
ANy chance that there will be a storyboard example anytime soon?