I have navigation bar i am setting title on image which is used in navigation bar it works fine but when i use same code for other controller it shows same previous title on navigation bar not the new one.
here is the code
UIImage *image = [UIImage imageNamed:#"Nav.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar addSubview:imageView];
titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(50,2,250,36)];
titleLabel.text=#"Activity";
titleLabel.textColor=[UIColor whiteColor];
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.font=[UIFont fontWithName:#"Helvetica-Bold" size :18];
[self.navigationController.navigationBar addSubview:titleLabel];
Related
Issue :
I have use below code to change Title and set underline of UIButton at run time.
[btnTemp setTitle:#"Test" forState:UIControlStateNormal];
I have got below issues:
Underline is not showing
Title not change
Title color is display default black.
To overcome this issue I have implement below code:
NSDictionary *attribs = #{NSForegroundColorAttributeName: _btnTemp.titleLabel.textColor,
NSFontAttributeName: _btnTemp.titleLabel.font,
NSUnderlineStyleAttributeName: #(NSUnderlineStyleSingle)
};
NSAttributedString *strAttributed = [[NSAttributedString alloc] initWithString:#"Test" attributes:attribs];
[btnTemp setAttributedTitle:strAttributed forState:UIControlStateNormal];
i want to set a navigation controller's right bar button item to image so i write a code like as
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"Button.png"]];
image.frame=CGRectMake(0, 25, 35, 40);
UIBarButtonItem *customButton = [[UIBarButtonItem alloc]initWithCustomView:image];
customButton.title=[NSString stringWithFormat:#"Hi"];
[customButton setImage:[UIImage imageNamed:#"Button.png"]];
it is like as i want but then button was not clickable.any solution for that????
UIImagePickerController, UIPopoverController,iPad
Inside my app, the photo view and the photos taken are as expected in Portrait mode, i.e. HomeButton
at the bottom. But with the iPad only, (iPhone is fine) if I use Landscape, and point the iPad camera at a ladder leaned up against the house, say from the ground to the eaves, the eaves are running vertically along the right side of the popOver camera view.
That is, the popover camera viewer has rotated into the correct position (long side of viewer are parallel to the long sides of the device, but the image displayed is rotated 90 degrees right.
How do I fix this problem?
Thanks for reading, Mark
- (IBAction)grabPhotoAction
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = (cameraSelected) ?
UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
self.myPopover = [[classPopoverController alloc] initWithContentViewController:imagePicker];
[myPopover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else {
[self presentViewController:imagePicker animated:NO completion:NULL];
}
}
I found the answer online just before posting this question. I decided it might well be helpful to others. The answer is quite simple. Forget all about using the special treatment for iPad and simply display full screen for both iPhone and iPad.
- (IBAction)grabPhotoAction
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = (_cameraSelected) ?
UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:NO completion:NULL];
}
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 360, 44)];
[imgView1 setImage:[UIImage imageNamed:#"bg.png"]];
self.navigationItem.titleView = imgView1;
My problem here is that Image on NavigationBar has some blabnk space at left side corner and its looking bad. So i wanna make the Image displayed on whole Navigation Bar and also if any buttons on Navigation Bar then image should come backgroud.
Can any body give me the solution for displaying UINavigationItem prompt text in 2 lines?
There is not a built-in way to do this. Below is a work-around that seems to work pretty well that I put together from stackOverflow post UINavigationItem with prompt and activity indicator
Here is a simulator screen shot of what it creates:
Note that since the text is a UILabel you can modify its color, font, or anything else too.
// I have this code in viewDidLoad
UIView *viewContainingPrompt;
UIBarButtonItem *promptButtonItem;
// Configuring the prompt title of the navigation bar so it is present but empty
[self.navigationItem setPrompt: #""];
// We will create a UIBarButtonItem that has a custom view (viewContainingPrompt).
// A subview of viewContainingPrompt will be a UILabel (headerLabel)
// We need to have this "intermediate" view to position the label at the right position
// (the UIBarButtonItem ignores the origin and height of its custom view)
viewContainingPrompt = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 0, 85)];
viewContainingPrompt.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Choose a width that puts 10 points on either end...
CGFloat labelWidth = self.navigationController.navigationBar.bounds.size.width - 20.0;
// Note that the '-60' below is determined by the width of the back button
// If someone can figure out how to determine this width at runtime this code
// would be much more robust.
UILabel *headerLabel = [[UILabel alloc] initWithFrame: CGRectMake(-60,-8,labelWidth,36)];
headerLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
headerLabel.text = #"A quite long prompt string that will wrap to a second line to demonstrate multiline prompt.";
headerLabel.font = [UIFont systemFontOfSize: 14];
headerLabel.numberOfLines = 0; // Zero gives as many lines as will fit, could be 2
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textColor = [UIColor colorWithRed: .1 green: .1 blue: .2 alpha: 0.8f];
headerLabel.shadowColor = [UIColor colorWithRed: 1 green: 1 blue: 1 alpha: 0.5f];
headerLabel.shadowOffset = CGSizeMake( 0, 1 );
headerLabel.textAlignment = UITextAlignmentCenter;
[viewContainingPrompt addSubview: headerLabel];
//[headerLabel release]; // Uncomment if not using ARC
promptButtonItem = [[UIBarButtonItem alloc] initWithCustomView: viewContainingPrompt];
self.navigationItem.leftBarButtonItem = promptButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;
//[viewContainingPrompt release]; // Uncomment if not using ARC
//[promptButtonItem release]; // Uncomment if not using ARC
I would appreciate anyone's feedback on how to figure out the width of the back button during execution so that width did not have to be hard coded.
As it is I do not think there are any private APIs or other illegal code contained.