Tôi cố gắng để thêm một nút thanh Ngay trong thanh tabbar tôi navigationbar
, và làm việc của nó tốt trong iphone 5 và thiết bị 5s và tất cả các mô phỏng. Nhưng nó không hiển thị trong iphone 6 và 6+ device.However làm việc tốt của nó trên giả lập của iphone 6 và 6+.nút thanh phải không xuất hiện trong iphone 6 và 6 +
Đây là mã nút.
@property (nonatomic, weak) UIButton *rightButton;
-(void)setNavigationBarRightButton
{
rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 40);
rightButton.layer.cornerRadius = 20;
rightButton.layer.borderColor = [[UIColor lightGrayColor] CGColor];
rightButton.layer.borderWidth = 2;
rightButton.imageView.layer.cornerRadius = 20;
rightButton.clipsToBounds = YES;
UIImage* image;
NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
if (imageData == (id)[NSNull null] || imageData.length == 0) {
NSLog(@"image data is %@",imageData);
image = [UIImage imageNamed:@"defaultIcon.png"];
}
else {
image = [UIImage imageWithData:imageData];
}
// rightButton.imageView.image = image;
[rightButton setBackgroundImage:image forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(onClickrighttButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.tabBarController.navigationItem.rightBarButtonItem = rightBarButtonItem;
}
- (void)onClickrighttButton:(id)sender
{
NSLog(@"clicked");
}
Bạn có thể nhìn thấy trong hình cũng
Cũng là một hình ảnh rõ ràng về iphone 6
Xem có thậm chí không giữ chỗ xuất hiện như là nút có đường viền của 2.
Bạn đã cố gắng xóa sạch dự án và có thể là dữ liệu có nguồn gốc? – Templar
Bạn không nên giữ một tham chiếu yếu. Hãy thử '@property (nonatomic) UIButton * rightButton;' – Desdenova
Tắt đầu của tôi, tôi nghĩ bạn nên đặt nó trên chính bộ điều khiển xem, không phải là bộ điều khiển thanh tab. Hoặc là hệ thống phân cấp của bạn thực sự Nav> Tab> Nội dung? –