gpt4 book ai didi

ios - 自定义导航栏后退按钮点击区域

转载 作者:行者123 更新时间:2023-12-01 18:57:28 25 4
gpt4 key购买 nike

  • 我已经实现了自定义后退导航栏按钮。
  • 代码:

    -(UIBarButtonItem *)logicToAddBackButton {
    UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UiNavigationBack"]];

    UILabel *label=[[UILabel alloc] init];

    [label setTextColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]];
    [label setText:@"Home"];
    [label sizeToFit];

    int space=6;
    label.frame=CGRectMake(imageView.frame.origin.x+imageView.frame.size.width+space, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, label.frame.size.width+imageView.frame.size.width+space, imageView.frame.size.height)];

    view.bounds=CGRectMake(view.bounds.origin.x+8, view.bounds.origin.y-1, view.bounds.size.width, view.bounds.size.height);
    [view addSubview:imageView];
    [view addSubview:label];

    UIButton *button=[[UIButton alloc] initWithFrame:view.frame];
    [button addTarget:self action:@selector(eventBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];

    [UIView animateWithDuration:0.33 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
    label.alpha = 0.0;
    CGRect orig=label.frame;
    label.frame=CGRectMake(label.frame.origin.x+25, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
    label.alpha = 1.0;
    label.frame=orig;
    } completion:nil];

    UIBarButtonItem *backButton =[[UIBarButtonItem alloc] initWithCustomView:view];

    return backButton;

    }

    self.navigationItem.leftBarButtonItem = [self logicToAddBackButton];
  • 根据逻辑,这是它的外观和工作方式。
  • 问题:如果单击箭头的前半部分,则后退按钮不响应。
  • 请对此提出建议。
  • 最佳答案

    尝试设置为您的按钮:

    button.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)

    关于ios - 自定义导航栏后退按钮点击区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25752292/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com