Nó luôn luôn làm việc cho tôi:
self.navigationItem.leftBarButtonItem = [self logicToAddBackButton];
GET DEFAULT LẠI NÚT
-
(UIBarButtonItem*) logicToAddBackButton
{
UIImageView *imageView;
// [imageView setTintColor:[UIColor redColor]];
UILabel *label=[[UILabel alloc] init];
if (WHITEBACK) {
imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UiNavigationBackIPAD"]];
[label setTextColor:[UIColor whiteColor]];
}else{ //DEFAULTBACK
imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UiNavigationBack"]];
[label setTextColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]];
}
[label setText:@"Back"];
[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);
UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(view.bounds.origin.x, view.bounds.origin.y,
view.bounds.size.width, view.bounds.size.height)];
button.bounds=CGRectMake(view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width,
view.bounds.size.height);
[button addTarget:self action:@selector(eventBack) forControlEvents:UIControlEventTouchUpInside];
[button addSubview:imageView];
[button addSubview:label];
[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 -5, label.frame.size.width,
label.frame.size.height+10);
label.alpha = 1.0;
label.frame=orig;
} completion:nil];
UIBarButtonItem *backButton =[[UIBarButtonItem alloc] initWithCustomView:button];
return backButton;
}
LẠI NÚT HÀNH ĐỘNG
(void) eventBack { [self.navigationController popViewControllerAnimated: YES]; }
UiNavigationBack Hình ảnh (Vui lòng thay đổi màu sắc của hình ảnh như yêu cầu với cùng một kích thước [25X41 144pixels/inch] để có được cái nhìn mặc định) ![enter image description here](https://i.stack.imgur.com/Av8zQ.png)
Nguồn
2014-12-22 13:03:17
Đó là những gì tôi đã làm, nhưng cùng một bộ điều khiển xem có thể kéo lên một bộ điều khiển xem Composer Mail, và nó thay đổi màu sắc của các nút ở đó, đi ngược lại không có quy tắc tùy chỉnh cho bộ điều khiển đó. – user717452
người đàn ông tuyệt vời ... cảm ơn rất nhiều. – harshitgupta