Created
February 9, 2012 06:28
-
-
Save tikitikipoo/1777840 to your computer and use it in GitHub Desktop.
iOSのツールバーを作成。背景に画像を指定。グラデーションをしたくなかったので1px*1pxの黒色画像(black.png)を用意。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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