1

它尝试了以下代码段来使用我自己的按钮自定义后退栏按钮。这没有效果,因为它看起来像默认的后退按钮。

    EKEventViewController*eventView = [[EKEventViewController alloc] initWithNibName:nil bundle:nil];
    eventView.event = closestEvent;
    eventView.allowsEditing = NO;
    UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setImage:[UIImage imageNamed:@"closeButton.png"] forState:UIControlStateNormal];
    leftButton.frame = CGRectMake(0, 0, 25, 25);
    [leftButton addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

    [self.navigationController pushViewController:eventView animated:YES];

我还尝试将 EKEventViewController 作为另一个视图控制器的子视图,我不知道如何正确处理它。无论哪种方式,我只想自定义后退按钮。

更新,我试过这个:

 eventView.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

可以工作,但随后会在右侧自动添加一个完成按钮(可能是在运行时?)我试图将右栏按钮归零但没有效果:

  eventView.navigationItem.rightBarButtonItem = nil;
4

2 回答 2

0

发生的情况是,当您推送 EKEventViewController 时,对象已分配,但视图尚未加载。我找到的解决方案是使用 UIAppearance API。尝试以下调用。

 NSDictionary *textAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};   
 [[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];

不幸的是,这将影响您应用中的所有 UIBarbuttonItems,并且以下代码对我不起作用。所以你可能必须手动设置 UIBarbuttonItem 的其他实例

这段代码对我不起作用

[[UIBarButtonItem appearanceWhenContainedIn:[EKEventViewController class], nil] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
于 2014-01-15T16:09:59.207 回答
0

当您按下事件视图控制器时,该Back按钮将默认显示标题为“返回”,因此您不必手动更改它。但是,如果您决定更改Back按钮,则可以通过将新的类型对象分配给导航项UIBarButtonItem的属性来实现。backBarButtonItem例如,您可以修改方法以在推送事件视图控制器之前pushController:为我们的根视图控制器提供一个自定义按钮。Back

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.eventStore = [[EKEventStore alloc]init];

    NSTimeInterval nsYear = 1 * 365 * 24.0f *60.0f * 60.0f;
    NSDate *startDate = [[NSDate date] dateByAddingTimeInterval:-nsYear];
    NSDate *endDate = [NSDate date];

    NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:self.eventStore.calendars];

    NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];

    if ([events count]> 0)
    {
        EKEvent *event = [events objectAtIndex:0];
        EKEventViewController *controller = [[EKEventViewController alloc]init];
        controller.event = event;
        controller.allowsEditing = YES;
        controller.allowsCalendarPreview = YES;
        controller.delegate = self;

        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Go BACK OK" style:UIBarButtonItemStylePlain target:nil action:nil];
        [self.navigationController pushViewController:controller animated:YES];

    }

}

希望,这会有所帮助。

于 2013-07-22T06:05:57.967 回答