I'm having some trouble with autoresizing masks. Here's the deal: I'm using the recently released TwUI
, which takes a lot from UIKit, but it's on the Mac. That's why I tagged for both iOS & Mac. So, I create a view that needs to have 40px of margin on the bottom, no matter how large the window is resized vertically. I'm not allowing horizontal expansion of the window, for multiple reasons. Here's what a sample looks like of what I'm talking about. Sorry for the ugly appearance, I'm just using sample views to test.
Right ho, so see the 40px of black space on the bottom?
I'm creating the red view by doing something like this:
CGRect b = self.view.bounds;
b.origin.y += TAB_HEIGHT; //40px
b.size.height -= TAB_HEIGHT;
Then I'm creating the view with that frame.
However, as soon as I try to add autoresizing masks on the red view it loses bottom 40px, and just fills the whole view. For those unfamiliar with TwUI
, a sample autoresizing mask looks like this:
view.autoresizingMask = TUIViewAutoresizingFlexibleHeight;
So, the autoresizing masks take after their iOS counterparts. However, setting that mask does this:
So my question is, how can I keep a margin on the bottom of this view?
@Rob, I have got no trouble autoresizing it.
The following code was what I modified an empty project with TwUI github trunk.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
TUINSView *content = [[TUINSView alloc] initWithFrame:CGRectZero];
CGRect b = [window frame];
b.origin = CGPointZero;
content.frame = b;
[window setContentView:content];
TUIView *viewA = [[TUIView alloc] initWithFrame:CGRectZero];
viewA.frame = content.bounds;
viewA.backgroundColor = [TUIColor blackColor];
[content setRootView:viewA];
viewA.autoresizingMask = TUIViewAutoresizingFlexibleSize;
TUIView *viewB = [[TUIView alloc] initWithFrame:CGRectZero];
viewB.backgroundColor = [TUIColor redColor];
b = viewA.bounds;
b.origin.y+=30;
b.size.height-=30;
viewB.frame = b;
[viewA addSubview:viewB];
viewB.autoresizingMask = TUIViewAutoresizingFlexibleSize;
}
EDIT: I coded my TUIViewController's loadView like this, it works so far so well.
- loadView {
TUIView *v = [[TUIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
tableView = [[TUITableView alloc] initWithFrame:v.bounds style:TUITableViewStylePlain];
[tableView scrollToTopAnimated:NO];
tableView.autoresizingMask = TUIViewAutoresizingFlexibleSize;
document = [[BBSDocDocument alloc] init];
tableView.delegate = self;
tableView.dataSource = self;
CGRect rect = [v bounds];
[v addSubview:tableView];
[self setView:v];
}
EDIT 2: My code with TUIViewController subclass:
//TestVC.h:
#import <Foundation/Foundation.h>
#import "TUIKit.h"
@interface TestVC : TUIViewController {
@private
TUIView *viewA;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
@end
//TestVC.m
@implementation TestVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nil bundle:nil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)loadView {
self.view = [[[TUIView alloc] initWithFrame:CGRectZero] autorelease];
self.view.autoresizingMask = TUIViewAutoresizingFlexibleSize;
}
//application delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
TUINSView *content = [[TUINSView alloc] initWithFrame:CGRectZero];
CGRect b = [window frame];
b.origin = CGPointZero;
content.frame = b;
[window setContentView:content];
TUIView *viewA = [[TUIView alloc] initWithFrame:CGRectZero];
viewA.frame = content.bounds;
viewA.backgroundColor = [TUIColor blackColor];
[content setRootView:viewA];
[viewA setAutoresizingMask:TUIViewAutoresizingFlexibleSize];
TUIView *viewB = [[TUIView alloc] initWithFrame:CGRectZero];
viewB.backgroundColor = [TUIColor redColor];
b = viewA.bounds;
b.origin.y+=30;
b.size.height-=30;
viewB.frame = b;
[viewA addSubview:viewB];
viewB.autoresizingMask = TUIViewAutoresizingFlexibleSize;
TestVC *testVC = [[TestVC alloc] initWithNibName:nil bundle:nil];
testVC.view.frame = viewB.bounds;
testVC.view.backgroundColor = [TUIColor yellowColor];
[viewB addSubview:testVC.view];
}