Cant set UISegmentedControl to be clear - uiview

What am I doing wrong to set the segmentedControl's colour to clear, it is currently black?
UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:#"Info", #"People", #"Photos", #"Items", nil]];
[control setFrame:CGRectMake(0, 45, self.frame.size.width, 40)];
[control setBackgroundColor:[UIColor clearColor]];
[control setSegmentedControlStyle:UISegmentedControlStyleBar];
[control setSelectedSegmentIndex:0];

Related

Space between uibarbuttons in navigation bar, Xcode 6.1

I have tried almost all answers here, How to remove the blank space between the two uibarbuttons shown below the code i use is
UIButton *backBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[backBTN addTarget:self action:#selector(backACT:) forControlEvents:UIControlEventTouchUpInside];
[backBTN setBackgroundImage:[UIImage imageNamed:#"menu_icon.png"] forState:UIControlStateNormal];
UIBarButtonItem *backkb = [[UIBarButtonItem alloc] initWithCustomView:backBTN];
// self.navigationItem.leftBarButtonItem = backkb;
UIButton *homeBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[homeBTN addTarget:self action:#selector(homeACT:) forControlEvents:UIControlEventTouchUpInside];
[homeBTN setBackgroundImage:[UIImage imageNamed:#"logout_btn.png"] forState:UIControlStateNormal];
UIBarButtonItem *btnhome = [[UIBarButtonItem alloc] initWithCustomView:homeBTN];
// btnhome.imageInsets = UIEdgeInsetsMake(-10, 0, 0, 0);
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: backkb, btnhome, nil]];
self.navigationItem.hidesBackButton = YES;
Try this,
// Create a UIView to add both buttons
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
UIButton *backBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[backBTN addTarget:self action:#selector(backACT:) forControlEvents:UIControlEventTouchUpInside];
[backBTN setBackgroundImage:[UIImage imageNamed:#"menu_icon.png"] forState:UIControlStateNormal];
//Add button to UIView
[leftView addSubview:backBTN];
UIButton *homeBTN= [[UIButton alloc] initWithFrame:CGRectMake(30, 0, 30, 30)];
[homeBTN addTarget:self action:#selector(homeACT:) forControlEvents:UIControlEventTouchUpInside];
[homeBTN setBackgroundImage:[UIImage imageNamed:#"logout_btn.png"] forState:UIControlStateNormal];
//Add button to UIView
[leftView addSubview:homeBTN];
//Set UIView as CustomView for bar button
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftView];
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: leftBarButton, nil]];
self.navigationItem.hidesBackButton = YES;
I have tried this and got output as
used some background colour to know the borders

Custom navigation bar back button hit area

I have implement custom back Navigation bar button.
Codes:
-(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];
This is how it look and work fine according to the logic.
Issue: If we click on first half of arrow, the back button do not respond.
Please suggest on this.
Try to set to your button:
button.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
I think you miscalculating frame somewhere.
Why don't you add UIButton instead? It will be much easier, but without label animation.
UIButton *button = [[UIButton alloc] init];
[button addTarget:self action:#selector(eventBack:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Home" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"UiNavigationBack"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
[button sizeToFit];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
return backButton;

Done button on UIToolBar does not operate - iOS

I am trying to create a picker with bar that has done button.
I tried to implement as follows;
viewForDatePicker = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 320, 266)];
[viewForDatePicker setBackgroundColor:[UIColor whiteColor]];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
toolBar.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:#selector(doneButtonPressed:)];
UIButton * doneButton =[[UIButton alloc]initWithFrame:CGRectMake(290, 2, 30, 20)];
[doneButton setBackgroundColor:[UIColor redColor]];
[doneButton addTarget:self action:#selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[viewForDatePicker addSubview:doneButton];
[toolBar setItems:[NSArray arrayWithObject:btn]];
[viewForDatePicker addSubview:toolBar];
birthDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 266)];
[birthDatePicker setDatePickerMode:UIDatePickerModeDate];
[birthDatePicker setBackgroundColor:[UIColor whiteColor]];
[viewForDatePicker addSubview:birthDatePicker];
[self.view addSubview:viewForDatePicker];
Unfortunately done button does not perform. What is wrong with this code?
Could you please help me
You are adding the button to the view first.
So when you add the date picker it is above the button. This is why the button is not responding to touch.
Change to this:
birthDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 266)];
[birthDatePicker setDatePickerMode:UIDatePickerModeDate];
[birthDatePicker setBackgroundColor:[UIColor whiteColor]];
[viewForDatePicker addSubview:birthDatePicker];
UIButton * doneButton =[[UIButton alloc]initWithFrame:CGRectMake(290, 2, 30, 20)];
[doneButton setBackgroundColor:[UIColor redColor]];
[doneButton addTarget:self action:#selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[viewForDatePicker addSubview:doneButton];
[toolBar setItems:[NSArray arrayWithObject:btn]];
[viewForDatePicker addSubview:toolBar];

How to change Bar Button Item colour?

In my detail view controller (part of navigation controller application) I've added custom "Back" button, like this:
- (void)loadView
{
[super loadView];
UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 10.0f, 24.0f)];
UIImage *backImage = [UIImage imageNamed:#"left_arrow_icon"];
[backButton setBackgroundImage:backImage forState:UIControlStateNormal];
[backButton setTitle:#"" forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(popBack) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backButtonItem;
}
-(void) popBack {
[self.navigationController popViewControllerAnimated:YES];
}
As you can see I added left bar button and assign "popBack" action. Basically left_arrow_icon is silver but when I press it, iOS change it darker grey.
My question is, can I (and how) change initial colour to white? Is that possible?
Edit. I use xcode5
Edit2:
That does't work too
Try this code. It works perfectly for me -
UIImageView *navigationBarImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Navigation.png"]];
navigationBarImage.frame = CGRectMake(0, 0, 320, 44);
navigationBarImage.userInteractionEnabled = YES;
navigationBarImage.backgroundColor = [UIColor colorWithRed:28.0/255.0 green:53.0/255.0 blue:102.0/255.0 alpha:1.0];
[self.view navigationBarImage];
[navigationBarImage release];
UIButton *backBarBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
backBarBtn1.frame = CGRectMake(13, 12, 20, 20);
[backBarBtn1 setImage:[UIImage imageNamed:#"ic_back3.png"] forState:UIControlStateNormal];
backBarBtn1.backgroundColor = [UIColor clearColor];
[backBarBtn1 addTarget:self action:#selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backBarBtn1];
Try this code -
[backbutton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:HELVETICA_REGULAR_FONT size:17.0], UITextAttributeFont, nil] forState:UIControlStateNormal];

Label keeps disappearing from my navigation menu

For some reason the label in my navigation bar keeps disappearing and only displaying my map icon and home button. Is it because I'm adding it as a barbuttonitem? Is there a way around this?
UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(160, 5, 250, 70)];
UILabel *l1=[[UILabel alloc]initWithFrame:CGRectMake(0,5, 310, 70)];
l1.text=#"FIND THINGS TO DO";
l1.font=[UIFont fontWithName:#"Helvetica Neue LT Std" size:25.0];
l1.backgroundColor=[UIColor clearColor];
l1.textColor=[UIColor whiteColor];
l1.textAlignment=UITextAlignmentCenter;
[view1 addSubview:l1];
UIBarButtonItem *left2=[[UIBarButtonItem alloc]initWithCustomView:view1];
self.navigationItem.rightBarButtonItem=left2;
[self.navigationItem setHidesBackButton:YES];
self.navigationItem.hidesBackButton=YES;
self.navigationController.navigationBarHidden = NO;
UIImage* image3 = [UIImage imageNamed:#"home_btn.png"];
homeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 18, 38, 38)];
[homeBtn setBackgroundImage:image3 forState:UIControlStateNormal];
[homeBtn addTarget:self action:#selector(Home)
forControlEvents:UIControlEventTouchUpInside];
[homeBtn setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *home = [[UIBarButtonItem alloc] initWithCustomView:homeBtn];
NSArray *arr=[[NSArray alloc]initWithObjects:home, nil];
self.navigationItem.rightBarButtonItems = arr;
UIImage* mapButton1 = [UIImage imageNamed:#"Top-Map-Icon.png"];
mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 18, 26, 30)];
[mapButton setBackgroundImage:mapButton1 forState:UIControlStateNormal];
[mapButton addTarget:self action:#selector(Map)
forControlEvents:UIControlEventTouchUpInside];
[mapButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *map = [[UIBarButtonItem alloc] initWithCustomView:mapButton];
NSArray *arr2 = [[NSArray alloc] initWithObjects:map, nil];
self.navigationItem.leftBarButtonItems = arr2;

Resources