-(void )SetNavBarView{
searchBarBtn.hidden=YES;
UIView *NavBarView ;
NavBarView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
btn1.titleLabel.font=[UIFont systemFontOfSize:14];
[btn1 setBackgroundImage:[UIImage imageNamed:#"list.png"] forState:UIControlStateSelected];
[btn1 setBackgroundImage:[UIImage imageNamed:#"nine_grid.png"] forState:UIControlStateNormal];
btn1.tag=10;
[btn1 addTarget:self action:#selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn1];
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(45, 0, 44, 44)];
btn2.titleLabel.font=[UIFont systemFontOfSize:14];
[btn2 setBackgroundImage:[UIImage imageNamed:#"map.png"] forState:UIControlStateNormal];
btn2.tag=11;
[btn2 addTarget:self action:#selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn2];
UILabel *labtitle=[[UILabel alloc]initWithFrame:CGRectMake(95, 0, 120, 44)];
labtitle.text=NSLocalizedString(#"people_nearby", nil);
labtitle.textColor=[UIColor whiteColor];
labtitle.backgroundColor=[UIColor clearColor];
labtitle.textAlignment=UITextAlignmentCenter;
labtitle.font=[UIFont boldSystemFontOfSize:20.0];
[NavBarView addSubview:labtitle];
UIButton *btn3 = [[UIButton alloc] initWithFrame:CGRectMake(135, 0, 95, 44)];
btn3.tag=12;
[btn3 addTarget:self action:#selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn3];
arrowImage=[[UIImageView alloc]initWithFrame:CGRectMake(75, 16, 10, 10)];
arrowImage.image=[UIImage imageNamed:#"arrow_down.png"];//arrow_down.png
[btn3 addSubview:arrowImage];
UIButton *btn4 = [[UIButton alloc] initWithFrame:CGRectMake(230, 0, 44, 44)];
btn4.titleLabel.font=[UIFont systemFontOfSize:14];
[btn4 setBackgroundImage:[UIImage imageNamed:#"ic_action_search.png"] forState:UIControlStateNormal];
btn4.tag=13;
[btn4 addTarget:self action:#selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn4];
// [bubble stretchableImageWithLeftCapWidth:20 topCapHeight:14]
UIButton *btn5 = [[UIButton alloc] initWithFrame:CGRectMake(275, 0, 44, 44)];
btn5.backgroundColor=[UIColor redColor];
[btn5 setBackgroundImage:[UIImage imageNamed:#"location.png" ] forState:UIControlStateNormal];
btn5.tag=14;
[btn5 addTarget:self action:#selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn5];
NavBarView.hidden=NO;
// [self.view addSubview:NavBarView];
self.navigationItem.titleView=NavBarView;
}
I have a UINavigationItem , which has five buttons. The fifth button btn5 can only click the left side, but the right of the btn5 cannot be clicked. ( Size of the button is 44 x 44 )
It's because of the size of UINavigationBarItem, it will by default leave a 14px around both sides. If you give a background color to your first button, then you see that space.
Related
viewForFooterInSection not showing into the bottom of the screen(uitableview).
here I am using UItableview.
Note: in below screen vary bottom of the screen one more footer added.(white color view).
Redcolorview: footer (from below code)
blue color: table background color
white bottom:
Red color view I added programmatically, using below code:
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForFooterInSection:(NSInteger)section
{
return 44;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
NSLog(#"%f",tableView.frame.size.width);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 44)];
view.backgroundColor = [UIColor redColor];
UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, tableView.frame.size.width/2 - 60, 30)];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(#"pothysapp_label_text_backgroundcolor",#"ApplicationSettings",[NSBundle mainBundle], nil)]];
[cancelButton addTarget:self
action:#selector(cancelDetails:)
forControlEvents:UIControlEventTouchUpInside];
cancelButton.titleLabel.font = [UIFont fontWithName:#"Roboto-Bold" size:15];
cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[view addSubview:cancelButton];
UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(tableView.frame.size.width/2 + 30, 7, tableView.frame.size.width/2 - 60, 30)];
[saveButton setTitle:#"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[saveButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(#"pothysapp_label_text_backgroundcolor",#"ApplicationSettings",[NSBundle mainBundle], nil)]];
[saveButton addTarget:self
action:#selector(saveDetails:)
forControlEvents:UIControlEventTouchUpInside];
saveButton.titleLabel.font = [UIFont fontWithName:#"Roboto-Bold" size:15];
saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[view addSubview:saveButton];
return view;
}
Try this instead of returning your custom view in viewForFooterInSection.
Add your custom view to table footer in ViewdidLoad()
self.tableview.tableFooterView =//Your CustomView;
I removed estimatedHeightForFooterInSection and viewForFooterInSection.
Instead of this i added view in viewdidload:
self.tableview.contentInset = UIEdgeInsetsMake(0, 0, -20, 0);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 15, self.view.frame.size.width, 30)];
view.backgroundColor = [UIColor whiteColor];
self.tableview.tableFooterView = view;
UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, self.view.frame.size.width/2 - 60, 30)];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:cancelButton];
UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2 + 30, 7, self.view.frame.size.width/2 - 60, 30)];
[saveButton setTitle:#"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:saveButton];
I'm trying to add a centered button in my navbar header, confused as to how I can do it
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *meImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:#"%#/me.png", kSelfBundlePath]];
UIBarButtonItem *meButton = [[UIBarButtonItem alloc] initWithImage:meImage style:UIBarButtonItemStylePlain target:self action:#selector(twitterButton)];
[self.titleView //i read this can be used to like set it but i havent been able to figure it out
help would be appreciated, pretty new
check this code
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
container.backgroundColor = [UIColor clearColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 44, 44)];
[btn setBackgroundImage:[UIImage imageNamed:#"button0.png"] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[btn setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
//add your spacer images and button1 and button2...
self.navigationItem.titleView = container;
You can try like this way
UIView *topView = [[UIView alloc]initWithFrame:CGRectZero];
UIButton * button = [[UIButton alloc]initWithFrame:CGRectZero];
[button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Title here" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button sizeToFit];
[topView addSubview:button];
[topView sizeToFit];
self.navigationItem.titleView = topView;
-(void)buttonAction:(Id) sender {
NSLog(#"button clicked");
}
I think its pretty straight, you can use titleView property of UINavigationItem :
-(void)addCenterButton {
UIImage *meImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:#"%#/me.png", kSelfBundlePath]];
UIButton *button = [[UIButton alloc] initWithFrame::CGRectMake(0, 0, 40, 20)];
[button setImage:meImage forState:UIControlStateNormal];
[button addTarget:self action:#selector(twitterButton) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = button;
}
UITextField is shown but not the UIButton.
How can I show the button ??
UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(30.0, 150, 300, 30.0)];
password.delegate = self;
[password setBorderStyle:UITextBorderStyleRoundedRect];
[password setClearButtonMode:UITextFieldViewModeAlways];
password.placeholder = #"Password";
[password setFont:[UIFont systemFontOfSize:10]];
[self.view addSubview:password];
//button
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;
[button addTarget:self action:#selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button = [UIButton buttonWithType: UIButtonTypeSystem];
[self.view addSubview:button];
Try to add BackgroundColor and TitleColor of button:
[button setBackgroundColor:[UIColor greenColor]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
you are intializing button two times.
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;
button = [UIButton buttonWithType: UIButtonTypeSystem];
Intialize system button and set its frame later.
UIButton *button = [UIButton buttonWithType: UIButtonTypeSystem];
button.frame = CGRectMake(30, 200 , 50, 50);
Hope this will help.
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
I have created a view programatically, and want to add 2 button on that view but while running app view, buttons on it are not presented. Here is my sample code, seems problem is with frame but how to adjust button frames according to the frame of view:
cv = [[UIView alloc]initWithFrame:CGRectMake(200, 60, 100, 80)];
UIButton *label1 = [[UIButton alloc]initWithFrame:CGRectMake(100,90, 200, 30)];
label1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[label1 setTitle: #"Mark as unread" forState: UIControlStateNormal];
label1.titleLabel.font=[UIFont fontWithName:#"SegoeUI" size:12.0];
[label1 addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
label1.backgroundColor=[UIColor blackColor];
[cv addSubview:label1];
UIButton *label2 = [[UIButton alloc]initWithFrame:CGRectMake(-50,20, 200, 30)];
[label2 setTitle: #"Mark as read" forState: UIControlStateNormal];
label2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
label2.titleLabel.font=[UIFont fontWithName:#"SegoeUI" size:12.0];
[label2 addTarget:self action:#selector(nonbuttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cv addSubview:label2];
First try this code, I have simply removed buttontype setting lines.
UIButton *label1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
//label1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *label2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 40, 100, 30)];
//label2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
Reason: label1 is getting created as per your frame in first line, and in next line, label1 is getting re-assigned to a new button instance created by buttonWithType method. Hence it was getting overridden over first instance where you have already set frames.
Hence your code will become like this:
cv = [[UIView alloc]initWithFrame:CGRectMake(200, 60, 100, 80)];
UIButton *label1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
[label1 setTitle: #"Mark as unread" forState: UIControlStateNormal];
label1.titleLabel.font=[UIFont fontWithName:#"SegoeUI" size:12.0];
[label1 addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
label1.backgroundColor=[UIColor blackColor];
[cv addSubview:label1];
UIButton *label2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 40, 100, 30)];
[label2 setTitle: #"Mark as read" forState: UIControlStateNormal];
label2.titleLabel.font=[UIFont fontWithName:#"SegoeUI" size:12.0];
[label2 addTarget:self action:#selector(nonbuttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cv addSubview:label2];