UIView
アプリケーション全体のさまざまな場所で使用できるカスタムがあります。基本的には次のようになります。
@interface BottomBar : UIView
{
UIImageView *imageView;
UILabel *nameLabel;
UIButton *playPauseButton;
}
@end
@implementation BottomBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(0.0, 524.0, 320.0, 44.0)];
if (self) {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15.0, 2.0, 40.0, 40.0)];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 2.0, 180.0, 40.0)];
playPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(265.0, 2.0, 40.0, 40.0)];
[self setBackgroundColor:[UIColor colorWithWhite:0.200 alpha:1.000]];
[imageView setImage:[UIImage imageNamed:@"NowPlaying.png"]];
[nameLabel setFont:[UIFont fontWithName:@"Helvetica Neue UltraLight" size:26.0]];
[nameLabel setShadowColor:[UIColor colorWithWhite:0.000 alpha:0.650]];
[nameLabel setShadowOffset:CGSizeMake(1.0, 2.0)];
[playPauseButton setUserInteractionEnabled:YES];
[playPauseButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
[playPauseButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:imageView];
[self addSubview:nameLabel];
[self addSubview:playPauseButton];
}
return self;
}
@end
いくつかのメソッドを省略しましたが、buttonPressed:(id)sender
メソッドは含まれています。心配しないでください。しかし、UIButton
はイベントにも、どのイベントにも応答しません。それ自体を強調することさえありません。
以前にnibファイルを介して初期化を行い、 (正常に機能した)とs[[[NSBundle mainBundle] loadNibNamed:@"BottomBar" [...]] objectAtIndex:0];
を接続しましたが、明らかに同様に機能しませんでした。IBOutlets
IBAction
それを解決する方法はありますか?
編集:UIViewController
フリーフォームとして定義されており、重複していないことは間違いありませんが、重複しているように見えるため、この部分により関連していると思います。UIWindow
色を赤に設定してテストしました。
とにかくコードは次のとおりです。
OverviewViewController *ovc = [[OverviewViewController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:ovc];
[[self window] setRootViewController:nvc];
bottomBar = [[BottomBar alloc] init];
[[self window] addSubview:bottomBar];
[[self window] bringSubviewToFront:bottomBar];
OverviewViewController は xib で 320x460 として定義されているため、バーの下部に 44px が必要です。
Edit2:いいえ、のサイズ変更は機能してUIViewController
いません。どのようにアイデアはありますか?