UIToolbar initWithFrame auto size?
I have noticed that in order to create a UIToolbar programmatically you need to set its size, for example with initWithFrame. Is there some way to have it auto compute the size so that on future (past?) versions of the OS everything will be the righ开发者_StackOverflow中文版t size? I am hesitant to effectively hard code the size of the toolbar.
Thanks!
Well, you can extend the UIToolbar-Class and then always instantiate your custom toolbar.
@interface CustomToolbar : UIToolbar {
…
}
- (id)initWithFullSize;
and the implementation like:
- (id)initWithFullSize {
self = [self initWithFrame:CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)];
return self;
}
and finally:
CustomToolbar *myToolbar = [[CustomToolbar alloc] initWithFullSize];
… something like this should do it.
精彩评论