Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created February 9, 2012 06:28
Show Gist options
  • Save tikitikipoo/1777840 to your computer and use it in GitHub Desktop.
Save tikitikipoo/1777840 to your computer and use it in GitHub Desktop.
iOSのツールバーを作成。背景に画像を指定。グラデーションをしたくなかったので1px*1pxの黒色画像(black.png)を用意。
CGFloat height = 45.0f;
CGRect toolBarBounds = CGRectMake(
self.view.bounds.origin.x,
//self.view.bounds.origin.y - 1.0f, // TOP表示時
self.view.bounds.origin.y + self.view.bounds.size.height - height, // Bottom表示時
self.view.bounds.size.width,
height
);
toolBar = [[UIToolbar alloc] initWithFrame:toolBarBounds];
[toolBar sizeToFit];
// 画像を指定
[toolBar setBackgroundImage: [UIImage imageNamed:@"black.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
toolBar.hidden = NO;
toolBar.multipleTouchEnabled = NO;
toolBar.autoresizesSubviews = YES;
toolBar.userInteractionEnabled = YES;
toolBar.barStyle = style;
// addSubviewしてね
// ボタン貼っつけたい場合は
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithTitle:@"ログイン" style:UIBarButtonItemStyleBordered target:self action:@selector(toolBarButtonTapped:)];
[item setTintColor:[UIColor blackColor]];
// ボタンをツールバーに貼っつけ
NSMutableArray* toolBarItems = [[NSMutableArray alloc] initWithCapacity:1];
[toolBarItems insertObject:item atIndex:0];
[item release];
[toolBar setItems:toolBarItems animated:NO];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment