iOS7.0.xでは、Navigation Bar にUIButtonを設置した場合、iOS6以前のコードではタイトル部分がNavigation Barの縦方向にセンタリングされない現象が起きるようになった。
また、フォント属性などを明示的に設定しないと、タイトル文字が表示されない。
例
UIButton *addBottun = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 41, 27)];
[addBottun setTitle:@"新規" forState:UIControlStateNormal];
[addBottun addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];
addBottun.backgroundColor = [UIColor clearColor];
[addBottun setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
addBottun.titleLabel.font = [UIFont fontWithName:@"AppleGothic" size:14];
addBottun.contentEdgeInsets = UIEdgeInsetsMake(5, 0, 0, 0);
UIButtonは、contentEdgeInsetsプロパティによりタイトル文字を下方向にずらして微調整する。
UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
UIBarButtonItem *cameraButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCamera target:self action:@selector(cameraAction)];
cameraButtonItem.imageInsets = UIEdgeInsetsMake(-30, 20, 0, 0);
UIBarButtonItemは、imageInsetsプロパティにより微調整する。
UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
【UIButtonの最新記事】

