Hi!I have used UIBarButton Image but i have got such kind of issue.i mean Image+button on backside.for that i have written code below.
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"mapbutton.png"] style:UIBarButtonItemStylePlain target:self action:#selector(btnMapClicked:)];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Use initWithCustomView and set a UIButton as the customView instead:
UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
subBtn.frame = CGRectMake(0, 0, 50, 40); //adjust as needed
[subBtn setImage:[UIImage imageNamed:#"mapbutton.png"] forState:UIControlStateNormal];
[subBtn addTarget:self action:#selector(btnMapClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithCustomView:subBtn];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Note that the sender in btnMapClicked: will now be a UIButton instead of a UIBarButtonItem.
Related
This is my code :
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"RETURN" style:UIBarButtonItemStylePlain target:self action:#selector(refreshPropertyList:)];
navigationController.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
[IpadAppDelegate.stackController presentModalViewController:navigationController animated:YES];
I find out the reason :
need change navigationController.navigationItem.rightBarButtonItem = anotherButton;
to: self.navigationItem.rightBarButtonItem = anotherButton;
Using the below code I am implementing my own Navigation Bar. For some reason when I run my app nothing is showing up for a back (left-arrow) button on the navigation bar. However if I change the code to leftBarButtonItem, the button does appear.
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
navigationItem.backBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
The backBarButtonItem is set by the parent ViewController.
In other words, it's not set by the ViewController on which you see it but by the ViewController to which it points. So if your ViewController is the first in line, it just won't have a back button.
Also, you are creating a NavigtionBar by yourself. This is usually not the way to go, a UINavigationBar isn't a UI-Element like a Button or a Label. You should rather use a UINavigationController to handle all the pushing and popping of your ViewControllers.
Figured it out:
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIButton *button = [UIButton buttonWithType:101];
// add selector
[button setTitle:#"Back" forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
navigationItem.leftBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
I am new in iphone...i have created toolbar with Four buttons...code is show
below...I want to add background image for each button. Anybody help me to create this..
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:#"About Me" style:UIBarButtonItemStyleBordered target:self action:#selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:#"Send Message" style:UIBarButtonItemStyleBordered target:self action:#selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:#"Block" style:UIBarButtonItemStyleBordered target:self action:#selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:#"About Me" style:UIBarButtonItemStyleBordered target:self action:#selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:#"Send Message" style:UIBarButtonItemStyleBordered target:self action:#selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:#"Block" style:UIBarButtonItemStyleBordered target:self action:#selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
UIImage *image = [UIImage imageNamed:#"audio-off.png"];
UIButton *myMuteButton = [UIButton buttonWithType:UIButtonTypeCustom];
myMuteButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[myMuteButton setImage:image forState:UIControlStateNormal];
[myMuteButton addTarget:self action:#selector(mute) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myMuteBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myMuteButton];
[buttons addObject:myMuteBarButtonItem];
[myMuteBarButtonItem release];
I have a toolbar where I want to post a textField. I'm trying with the following code but it doesn't work:
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:#"Item" style:UIBarButtonItemStyleBordered target:self action:#selector(action:)];
UITextField *customItem1 = [[UITextField alloc] init];
NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil];
[self setToolbarItems:items animated:YES];
The toolbar items must all be UIBarButtonItems. In order to display something else, you embed a view into the item:
UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view];
//view is the embedded view, in your case a UITextField
I am working on orientation of actionsheet with pickerview. It is working finely on potrait mode but it is not working on landscape mode. May I know where i went wrong?
Regards,
sathish
- (IBAction)openActionSheet
{
UIView *ui_pickerview = [[[UIView alloc] initWithFrame:CGRectMake(0, 160, 320, 305)] autorelease];
pickerViewPopup = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIImageView *pickerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,213)];
pickerImageView.image = [UIImage imageNamed:#"picker.png"];
UIImageView *homeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,137,30,24)];
homeImageView.image = [UIImage imageNamed:#"picker_icon_home.png"];
m_pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,44,0,0)];
m_pickerView.delegate = self;
//m_pickerView.dataSource = self;
m_pickerView.showsSelectionIndicator = NO;
//pickerView.
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleDefault;
pickerToolbar.tintColor = [UIColor colorWithRed:134/255.0 green:187/255.0 blue:34/255.0 alpha:1];
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(DonePicker:)];
[barItems addObject:doneBtn];
[doneBtn release];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(closePicker:)];
[barItems addObject:cancelBtn];
[cancelBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:m_pickerView];
//[pickerViewPopup addSubview:pickerImageView];
[pickerImageView release];
//[pickerViewPopup addSubview:homeImageView];
[homeImageView release];
[pickerViewPopup showInView:ui_pickerview];
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
}
If you are not adding your UIActionSheet to a view controller that is handling the orientation for landscape, then the UIActionSheet will come up in portrait.