2

iOS 7 に移行するアプリがあります。ただし、UIBarbuttonItems にはタイトルがありませんが、正常に動作しています。これが私のコードです:

UIBarButtonItem * uibbShare = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sharewhite.png"] style:UIBarButtonItemStylePlain target:self action:@selector(sharePressed:)] autorelease];
// uibbShare.width = 56.0;  // uncommenting this doesn't change anything
uibbShare.title = @"Share";

次に、これらのいくつかをツールバーに追加し、その間にいくつかの柔軟なスペース アイテムを配置します。

...
 [items addObject:flex2];
 [items addObject:uibbShare];
...

[self.toolbar setItems:items animated:NO];

iOS 7 ではタイトルがまったくありませんが、iOS6 ではすべて正常に動作しています。このようなバーボタンを ios7 で作成できなくなりましたか?

Dev Forums で同じ問題を更新します。

UIBarButtonItem はタイトルと画像の両方を持つことはできませんか?

ツールバー アイコンの下のテキストはどうなりましたか?

編集:(7対6)

ここに画像の説明を入力

編集2:(Revealの写真、テキストがなくなったようで、フレーム/境界は0.wtfです)

ここに画像の説明を入力

4

3 に答える 3

1

最終的に、UIBarButtonItems のカスタムビューを作成することになりました。良くはありませんが、一時的に機能します。新しい UIBarButtonItems を返すこの関数に古い UIBarButtonItems を渡すだけです。

注: タイトルがある場合はボタンの画像を上に移動し、下に単純なラベルを追加します。実際には titleEdgeInsets と centering を台無しにしません。また、幅をデフォルトの 56 に設定しています。

-(UIBarButtonItem *)convertToButton:(UIBarButtonItem *)original
{
    if ( SYSTEM_VERSION_LESS_THAN(@"7.0"))
        return  original;

    CGFloat textFieldHeight = 13.f;
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 56, self.toolbar.frame.size.height);
    button.showsTouchWhenHighlighted = YES;
    [button setImage:original.image forState:UIControlStateNormal];
    [button addTarget:original.target action:original.action forControlEvents:UIControlEventTouchUpInside];
    button.tag = original.tag;

    UIView * wr = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 56, self.toolbar.frame.size.height)] autorelease];
    [wr addSubview:button];
    wr.backgroundColor = [UIColor clearColor];

    if (original.title != nil)
    {
        button.imageEdgeInsets = UIEdgeInsetsMake(-7, 0, 0, 0);
        UILabel * l = [[[UILabel alloc] initWithFrame:CGRectMake(0, self.toolbar.frame.size.height - textFieldHeight, 56, textFieldHeight)] autorelease];
        l.font = [UIFont systemFontOfSize:11.f];
        l.backgroundColor = [UIColor clearColor];
        l.textColor = [UIColor lightGrayColor];
        l.textAlignment = UITextAlignmentCenter;
        l.text = original.title;
        [wr addSubview:l];
    }

    UIBarButtonItem * theNew = [[[UIBarButtonItem alloc] initWithCustomView:wr] autorelease];
    theNew.tag = original.tag;
    theNew.width = 56;
    return theNew;

}
于 2013-10-09T12:28:18.660 に答える
0

ボタンの外観を変更してみてください。

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor textColor], UITextAttributeTextColor, [UIFont yourFont and yourSizeSont], UITextAttributeFont, [UIColor shadowColor], UITextAttributeTextShadowColor, [NSValue valueWithCGSize:CGSizeMake(0.0, -1.0)], UITextAttributeTextShadowOffset, nil] forState:UIControlStateNormal];

私の最後のコメントに続いて、私は次のようなことを考えました:

NSArray *views = [_UIToolbarNavigationButton subviews];

for (UIView *view in views) {
    if ([view isKindOfClass:[UIButtonLabel class]])
    {
        view.hidden = NO;
    }
}

役に立つかどうかはわかりません。

于 2013-10-02T10:20:25.933 に答える
0
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont 
    fontWithName:@"YOURFONT" size:14], NSFontAttributeName, 
    [UIColor whiteColor], NSForegroundColorAttributeName, nil];

[[UINavigationBar の外観] setTitleTextAttributes:attributes]; 重要なのは、NSFontAttributeName などを使用することです。64 ビット互換性のために NS の種類を使用するように移行していると思います。上記のコードは私の iOS7 デバイスで動作しました

于 2013-10-02T10:17:58.200 に答える