Мне нужно что-то вроде «<Доставка» - стрелка, которая представляет собой кнопку возврата с меткой сбоку слева, но вместо этого я получаю что-то вроде «<Доставка»
Я много искал, но не нашел ничего полезного, что работало. позвольте мне показать вам код до сих пор.
// setting up background image of backbutton
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"Gallery--arrow.png"] ;
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0,8,15);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;
// ends
// text beside back button in header
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,150,30)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"GoodMobiPro-CondBold" size:24];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentLeft;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = selectedArea;
[label sizeToFit];
Пожалуйста, помогите и заранее спасибо.
3 ответа
Почему вы не можете использовать подобное?
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,150,30)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"GoodMobiPro-CondBold" size:24];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentLeft;
label.textColor = [UIColor whiteColor];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:label] ;
self.navigationItem.leftBarButtonItem = backButton;
//back button first
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"Gallery--arrow.png"] ;
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0,8,15);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
//then label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"<";
// other properties , fonts , background etc
[label sizeToFit];
UIBarButtonItem *leftLabelBarButton = [[UIBarButtonItem alloc] initWithCustomView:label target:yourTarget selector:yourSelector];
Now set self.navigationItem.leftBarButtonItems = @[backButton,leftLabelBarButton];
Предыдущее объяснение
Вам нужно использовать [UIBarButton alloc] initWithCustomView:
там, где вы передаете свой собственный UILabel
в качестве пользовательского представления
А затем установите
self.navigationItem.leftBarButtonItems = @[customViewBarButton,imageBarButton];
Таким образом, вы можете разместить метку и изображение в левой части панели навигации.
Пожалуйста, попробуйте описанный ниже метод и сообщите мне результат.
UIView * customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
customView.backgroundColor = [UIColor clearColor];
UIButton * customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
customButton.frame = CGRectMake(0, 0, 100.0, 30.0);
[customButton addTarget:self action:@selector(backSelected:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:customButton];
UILabel * customLabel = [[UILabel alloc] initWithFrame:CGRectMake(customButton.frame.origin.x + customButton.frame.size.width, customButton.frame.origin.y, 200.0, 30.0)];
customLabel.backgroundColor = [UIColor clearColor];
customLabel.text = @"Your title";
[customView addSubview:customLabel];
UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
self.navigationItem.leftBarButtonItem = leftItem;
leftItem = nil;
Благодарность!
Похожие вопросы
Новые вопросы
ios
iOS - мобильная операционная система, работающая на Apple iPhone, iPod touch и iPad. Используйте этот тег [ios] для вопросов, связанных с программированием на платформе iOS. Используйте связанные теги [target-c] и [swift] для проблем, характерных для этих языков программирования.