导航按钮文本阴影不会出现iOS 7

时间:2013-09-30 22:26:20

标签: ios objective-c uinavigationbar

到目前为止,我已经更新了应用程序的导航栏后退按钮项目,以便在iOS 7中查看,因为它在iOS 6中显示,但我无法在iOS 7中显示文本阴影。

iOS 7: enter image description here

iOS 6: enter image description here

(测试时偏移量变大)

代码:

    UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 80.0f + width_offset, 30.0f)];
    UIImage *buttonImage = [[UIImage imageNamed:@"navigation_back_btn"]  resizableImageWithCapInsets:UIEdgeInsetsMake(5, 15, 5, 5)];
    [backButton setBackgroundImage:buttonImage  forState:UIControlStateNormal];
    [backButton setTitle:title forState:UIControlStateNormal];
    [backButton.titleLabel setFont:[UIFont defaultFontWithType:kFontBold andSize:12]];
    [backButton.titleLabel setTextColor:[UIColor whiteColor]];
    [backButton.titleLabel setShadowColor = [UIColor blackColor]];
    [backButton.titleLabel setShadowOffset:CGSizeMake(5.0f, 5.0f)];
    [backButton addTarget:viewController action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    viewController.navigationItem.leftBarButtonItem = backButtonItem;

我还想将按钮向左移动,但这并不重要。

1 个答案:

答案 0 :(得分:4)

尝试在UIButton本身上设置标题阴影颜色:

[backButton setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];