how to add items in uinavigationbar at a specific position? - iphone

I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.
What i want is in following images
in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar.
There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.
Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.
So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..

you can add Multiple UIlabel or Image as look like bellow image:-
this can do using bellow code you can change Label and imageView frame and put as your requirement
- (void)viewDidLoad
{
UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = #"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = #"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:#"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];
self.navigationItem.titleView = btn;
}

You can add subviews directly to the navigationBar -
UINavigationBar *navBar = navController.navigationBar;
[navBar addSubview: yourLabel];
yourLabel frame origin will be relative to the navigation bar

Try this code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame: CGRectMake(160, 7 , 40, 30)];
[button0 setTitle:#"Sort" forState:UIControlStateNormal];
button0.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12];
[button0 setBackgroundImage:[UIImage imageNamed:#"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:#selector(sortAction) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
self.navigationItem.titleView = buttonContainer;
UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)];
lbl_title.text = str_HeaderTitle;
lbl_title.textColor = [UIColor whiteColor];
lbl_title.font = [UIFont fontWithName:#"Helvetica-Bold" size:16];
lbl_title.backgroundColor = [UIColor clearColor];
lbl_title.textAlignment = NSTextAlignmentCenter;
[buttonContainer addSubview:lbl_title];

You can set an arbitrary view instead of a view controller's title:
myViewController.navigationItem.titleView = someView;
Note that most likely the view's frame will be restricted to make room for leftBarButtonItem and rightBarButtonItem.

UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)];
[label setBackgroundColor:[UIColor greenColor]];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)];
[imgView setBackgroundColor:[UIColor redColor]];
[[self.navigationController navigationBar] addSubview:label];
[self.navigationController.navigationBar addSubview:imgView];

Have a look at this piece of code. With some modifications it should solve your problem:
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:CGRectMake(15, 0, 57, 44)];
[imageButton setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
[titleLabel setText:#"some title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[self.navigationController.navigationBar addSubview:imageButton];
[self.navigationController.navigationBar addSubview:titleLabel];
Just modify the values in the CGRectMake() to fit your needs.

Related

create button,text field and insert images programmatically in Xcode

I am facing trouble unexpected issue in iphone app. for whatever reason, I compile this, I get a SIGABRT error. it happens on the:
textFieldRounded=[[UITextField alloc]initWithframe: CGRectMake(20,50,280,31)];
textFieldRounded.borderStyle=UITextBorderStyleRoundedRect;
textFieldRounded.textColor=[UIColor blackColor];
textFieldRounded.font=[UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder=#"enter your name";
textFieldRounded.backgroundColor=[UIColor whiteColor];
textFieldRounded.autocorrectionType=UITextAutocorrectionTypeNo;
textFieldRounded.backgroundColor=[UIColor clearColor];
textFieldRounded.keyboardType=UIKeyboardTypeDefault;
textFieldRounded.returnKeyType=UIReturnKeyDone;
textFieldRounded.clearButtonMode=UITextFieldViewModeWhileEditing;
[self.view addSubView:textFieldRounded];
textFieldRounded.delegate=self;
UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(buttonPressed:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Button" forstate:UIControlStateNormal];
button.frame = CGRectMake(20,108,97,37);
[self.view addSubview:button];
label= [[UILabel alloc] initWithFrame:CGRectMake(40,243,240,21)];
label.backgroundColor=[UIColor clearColor];
label.textAlignment,UITextAlignmentCenter;
label.text=#"Label";
[self.view addSubview:label];
CGRect myImageRect = CGRectMake(40.0f,190.0f,240.0f,128.0f);
image= [[UIImageView alloc] initWithFrame:myImageRect];
[image setImage:[UIImage imageNamed:#"Default#2x.png"]];
image.backgroundColor=[UIColor clearColor];
image.opaque =YES;
image.alpha=0;
[self.view addSubview:image];
[image release];
}
you can Creat UITextField, UIButton or UILabel like this bellow code:-
UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = #"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[self.view addSubview:textField];
[textField release];
UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"UIButton" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
[button release];
UILabel
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 240, 300, 30)];
[self.view addSubview:headingLabel];
// Optional
headingLabel.text = #"WELCOME";
headingLabel.textColor = [UIColor orangeColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blueColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
UIImageView
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
myImage.image = [UIImage imageNamed:#"myImage.png"];
[self.view addSubview:myImage];
[mymyImage release];
Hope its helps you

Change the Font of UINavigationBar title

i am having this code to show the button as the title of the navbar,and then in button code i write the code to change the font of the unbutton text label.but i didn't get the correct font version with the below code.
UIButton *titleButton = [[UIButton alloc]init];
titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setFrame:CGRectMake(0, 0, 170, 35)];
[titleButton setTitle:[NSString stringWithFormat:#"%# %#",delegatee.selectedBook,delegatee.selectedChapter]forState:UIControlStateNormal];
titleButton.titleLabel.font =[UIFont fontWithName:#"Georgia" size:10.0f];
[titleButton addTarget:self action:#selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleButton;
iput georgia but i didn't get the correct font
Thanks.
Try this :
UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setFrame:CGRectMake(0, 0, 170, 35)];
[titleButton setTitle:[NSString stringWithFormat:#"%# %#",delegatee.selectedBook,delegatee.selectedChapter]forState:UIControlStateNormal];
titleButton.titleLabel.font =[UIFont fontWithName:#"Georgia" size:10.0f];
[titleButton addTarget:self action:#selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleButton;
try this
for button :- use in Navigation Title view , this is work IOS 4 and IOS 5 ,I use .....
UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setFrame:CGRectMake(0, 0, 170, 35)];
[titleButton setTitle:#"dee"forState:UIControlStateNormal];
UIFont *font=[UIFont fontWithName:#"A_Nefel_Sereke" size:21];
titleButton.titleLabel.font =font;
titleButton.titleLabel.textColor = [UIColor redColor];
[titleButton addTarget:self action:#selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleButton;
I think you have problem in your font name ... Please check
Why don't you just put a label instead of a button as the title ?
Here's code for a title label:
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView)
{
titleView = [[UILabel alloc] initWithFrame:CGRectZero];
[titleView setBackgroundColor:[UIColor clearColor]];
[titleView setFont:[UIFont fontWithName:#"Georgia" size:10.0f]];
[self.navigationItem setTitleView:titleView];
[titleView release];
}
titleView.text = title;
If you need it to be UIButton, it shouldn't be too hard to adjust the code to your needs.
Good luck !

How to add Customized View in UIAlertView

I have created a View containing labels and buttons with Controller.
By using addSubView method my view appears but button does not respond to view controller.. Can anybody help me doing what I want to do??
I have used this code to add view as subview in my alert view.
[myAlertView addSubview:myViewController.view];
You need to add an action on your button like below.
[yourButton addTarget:self action:#selector(myAction) forControlEvents:UIControlEventTouchUpInside];
- (IBAction) myAction
{
//Action to perform when yourButton pressed.
}
Hope this helps you!
myview=[[UIView alloc] init];
[myview setFrame:CGRectMake( 50.0f, 50.0f, 120.0f, 120.0f)];
[UIView commitAnimations];
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.7];
[myview setFrame:CGRectMake( 90.0f, 20.0f, 280.0f, 170.0f)];
myview.backgroundColor=[UIColor whiteColor];
//myview.frame = CGRectMake(10, 10, 200, 250);
[self.view addSubview:myview];
UIColor *forBackground = [UIColor colorWithPatternImage:[UIImage imageNamed:#"apple_bg.png"]];
[myview setBackgroundColor:forBackground];
myview.layer.cornerRadius=20;
myview.clipsToBounds=YES;
myview.layer.borderWidth = 2;
myview.layer.borderColor = [[UIColor whiteColor] CGColor];
UITextView *mytext = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 10.0, 160.0, 25.0)];
mytext.backgroundColor = [UIColor clearColor];
mytext.textColor = [UIColor blackColor];
mytext.editable = NO;
mytext.scrollEnabled=NO;
mytext.scrollEnabled=NO;
mytext.font = [UIFont systemFontOfSize:15];
mytext.text = #"First label";
[mytext release];
[myview addSubview:mytext];
entered = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 15.0, 150.0, 25.0)];
[entered setBackgroundColor:[UIColor whiteColor]];
entered.layer.cornerRadius = 10;
entered.textAlignment = UITextAlignmentCenter;
entered.clipsToBounds = YES;
[entered addTarget:self action:#selector(textDidChange:)forControlEvents:UIControlEventEditingChanged];
[myview addSubview:entered];
UITextView *mytext2 = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 50.0, 160.0, 25.0)];
mytext2.backgroundColor = [UIColor clearColor];
mytext2.textColor = [UIColor blackColor];
mytext2.editable = NO;
mytext2.scrollEnabled=NO;
mytext2.font = [UIFont systemFontOfSize:15];
mytext2.text = #"Second label";
[myview addSubview:mytext2];
[mytext2 release];
entered1 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 55.0, 150.0, 25.0)];
[entered1 setBackgroundColor:[UIColor whiteColor]];
entered1.layer.cornerRadius = 10;
entered1.textAlignment = UITextAlignmentCenter;
entered1.clipsToBounds = YES;
[myview addSubview:entered1];
[entered1 release];
UITextView *mytext3 = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 90.0, 160.0, 25.0)];
mytext3.backgroundColor = [UIColor clearColor];
mytext3.textColor = [UIColor blackColor];
mytext3.editable = NO;
mytext3.scrollEnabled=NO;
mytext3.font = [UIFont systemFontOfSize:15];
mytext3.text = #"Third Label";
[myview addSubview:mytext3];
[mytext3 release];
entered2 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 95.0, 150.0, 25.0)];
[entered2 setBackgroundColor:[UIColor whiteColor]];
entered2.layer.cornerRadius = 10;
entered2.clipsToBounds = YES;
entered2.text=#"Active";
entered2.textAlignment = UITextAlignmentCenter;
[myview addSubview:entered2];
[entered2 release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(EditTable:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Ok" forState:UIControlStateNormal];
button.frame = CGRectMake(60.0, 130, 60, 30);
[myview addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self action:#selector(EditTable1:)
forControlEvents:UIControlEventTouchDown];
[button1 setTitle:#"Cancel" forState:UIControlStateNormal];
button1.frame = CGRectMake(150.0, 130, 60, 30);
[myview addSubview:button1];
[self.view addSubview: myview];

-[CALayer release]: message sent to deallocated instance

I'm having a problem with some code in the loadView: method of one of my view controllers. Essentially I have a view which centres itself in a larger view (on an iPad) and has some labels, buttons and icons which are programmatically loaded into it.
The problem occurs when the view controller calls the dealloc method, and tries to release. I get a -[CALayer release]: message sent to deallocated instance error and the application crashes.
From reading up about this error, it appears I am over-releasing something, but I don't think that's the case: the code below is the trouble maker and I've tried both autorelease and manual release calls on everything, as well as simply not releasing them (I know, I know, that's bad) but it continues to cause havok.
container = [[UIView alloc] initWithFrame:CGRectNull];
container.autoresizingMask = ( UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin );
container.frame = CGRectMake( (viewSize.width-320)/2, (viewSize.height-480)/2, 320, 480);
[self.view addSubview:container];
UILabel *welcomeTo = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
welcomeTo.backgroundColor = [UIColor clearColor];
welcomeTo.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:18.0];
welcomeTo.frame = CGRectMake(23, 15, 103, 24);
welcomeTo.shadowColor = [UIColor blackColor];
welcomeTo.shadowOffset = CGSizeMake( 0, 1 );
welcomeTo.text = #"Welcome to";
welcomeTo.textAlignment = UITextAlignmentLeft;
welcomeTo.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:welcomeTo];
UILabel *progressions = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
progressions.backgroundColor = [UIColor clearColor];
progressions.font = [UIFont fontWithName:#"HelveticaNeue-BoldItalic" size:44.0];
progressions.frame = CGRectMake(20, 30, 280, 56);
progressions.shadowColor = [UIColor blackColor];
progressions.shadowOffset = CGSizeMake( 0, 1 );
progressions.text = #"Progressions";
progressions.textAlignment = UITextAlignmentCenter;
progressions.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:progressions];
UILabel *blurb = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
blurb.backgroundColor = [UIColor clearColor];
blurb.font = [UIFont fontWithName:#"HelveticaNeue" size:14.0];
blurb.frame = CGRectMake(23, 100, 274, 51);
blurb.numberOfLines = 3;
blurb.shadowColor = [UIColor blackColor];
blurb.shadowOffset = CGSizeMake( 0, 1 );
blurb.text = #"Kick off the fun by adding some content, or if you're not sure what you're doing, check out the \"Getting Started\" guide!";
blurb.textAlignment = UITextAlignmentLeft;
blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:blurb];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(20, 170, 280, 88)];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:#selector(createChart:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button1];
[button1 release];
UIImageView *icon1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addchart.png"]];
icon1.frame = CGRectMake(30, 180, icon1.frame.size.width, icon1.frame.size.height);
[container addSubview:icon1];
[icon1 release];
UILabel *button1title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 185, 180, 20)] autorelease];
button1title.backgroundColor = [UIColor clearColor];
button1title.font = [UIFont boldSystemFontOfSize:17.0];
button1title.shadowColor = [UIColor blackColor];
button1title.shadowOffset = CGSizeMake( 0, 1 );
button1title.text = #"Create a Chart";
button1title.textAlignment = UITextAlignmentLeft;
button1title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1title];
UILabel *button1blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 205, 180, 40)] autorelease];
button1blurb.backgroundColor = [UIColor clearColor];
button1blurb.font = [UIFont systemFontOfSize:13.0];
button1blurb.numberOfLines = 2;
button1blurb.shadowColor = [UIColor blackColor];
button1blurb.shadowOffset = CGSizeMake( 0, 1 );
button1blurb.text = #"A cheat sheet for a displaying a song in any key.";
button1blurb.textAlignment = UITextAlignmentLeft;
button1blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1blurb];
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(20, 270, 280, 88)];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button2 addTarget:self action:#selector(createSet:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button2];
[button2 release];
UIImageView *icon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addset.png"]];
icon2.frame = CGRectMake(30, 280, icon2.frame.size.width, icon2.frame.size.height);
[container addSubview:icon2];
[icon2 release];
UILabel *button2title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 285, 180, 20)] autorelease];
button2title.backgroundColor = [UIColor clearColor];
button2title.font = [UIFont boldSystemFontOfSize:17.0];
button2title.shadowColor = [UIColor blackColor];
button2title.shadowOffset = CGSizeMake( 0, 1 );
button2title.text = #"Create a Set";
button2title.textAlignment = UITextAlignmentLeft;
button2title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2title];
UILabel *button2blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 305, 180, 40)] autorelease];
button2blurb.backgroundColor = [UIColor clearColor];
button2blurb.font = [UIFont systemFontOfSize:13.0];
button2blurb.numberOfLines = 2;
button2blurb.shadowColor = [UIColor blackColor];
button2blurb.shadowOffset = CGSizeMake( 0, 1 );
button2blurb.text = #"A collection of charts that can be displayed like a book.";
button2blurb.textAlignment = UITextAlignmentLeft;
button2blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2blurb];
UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(20, 370, 280, 40)];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmall.png"] forState:UIControlStateNormal];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmallHighlighted.png"] forState:UIControlStateHighlighted];
[button3 addTarget:self action:#selector(gettingStarted:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button3];
[button3 release];
UILabel *button3title = [[[UILabel alloc] initWithFrame:CGRectMake(20, 370, 280, 36)] autorelease];
button3title.backgroundColor = [UIColor clearColor];
button3title.font = [UIFont boldSystemFontOfSize:17.0];
button3title.shadowColor = [UIColor blackColor];
button3title.shadowOffset = CGSizeMake( 0, 1 );
button3title.text = #"Getting Started";
button3title.textAlignment = UITextAlignmentCenter;
button3title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button3title];
UILabel *version = [[[UILabel alloc] initWithFrame:CGRectMake(20, 420, 280, 20)] autorelease];
version.backgroundColor = [UIColor clearColor];
version.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:12.0];
version.shadowColor = [UIColor blackColor];
version.shadowOffset = CGSizeMake( 0, 1 );
version.text = [NSString stringWithFormat:#"Version v%# (%#)", [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"], kRevisionNumber];
version.textAlignment = UITextAlignmentCenter;
version.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:version];
The container property is released in the dealloc method, as follows:
- (void)dealloc {
[leather release];
[backButton release];
[container release];
[super dealloc];
}
Any answers or suggestions people can provide would be greatly appreciated! I am truly stumped.
Profile your application in the simulator with 'Zombies' Instrument.
Run your app for a while and do whatever you have to do to make your app crash. When it does, you will get a pop up like the image below and it will halt the profiling of the app:
Then if you click on the little arrow next to the address (0x158b3c00) .. it will take you to the object retain/release history for the object that was over released (the zombie).
If you highlight the line above where the retain count went to -1, and open View -> Extended detail, it should point you to the stack trace and line in your code where the object was overreleased:
If you double click the class where it is occuring, it will open up your source and show you the bad line of code:
The over-releasing could be occurring during the objects life time and not just when they're being created. A few tips:
use accessors to ensure that pointers are set to nil
be consistent with your use of release/autorelease. Personally I prefer to have [[[Class alloc] init] autorelease] all on 1 line.
Learn the difference between release/autorelease. Let's Build NSAutoreleasePool is a good place to start.

Adding a UILabel onto a UINavigationController

I want to draw a long string of text underneath the Title on a UINaviagtionController.
I tried adding a UILabel to by doing :
[appDelegate.NavControll.view addSubview:testLabel];
And the Label appears but doesn't animate/move with the navbar and just seems independent of it.
Is there a way to achieve this or should I leave it alone and come up with another idea for displaying this string somewhere else.
Many Thanks,
Code
Looks a little bit ugly, but it works
You can easily customize appearance by yourself:
self.navigationItem.title = #"Needed title"; // for back button on pushed view
UIView *customTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = #"Title";
titleLabel.font = [UIFont fontWithName:#"Helvetica" size:18];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.center = CGPointMake(30, 10);
[titleLabel sizeToFit];
[customTitleView addSubview:titleLabel];
[titleLabel release];
UILabel *detailsLabel = [[UILabel alloc] init];
detailsLabel.text = #"details";
detailsLabel.font = [UIFont fontWithName:#"Helvetica" size:9];
detailsLabel.backgroundColor = [UIColor clearColor];
[detailsLabel sizeToFit];
detailsLabel.center = CGPointMake(50, 35);
[customTitleView addSubview:detailsLabel];
[detailsLabel release];
self.navigationItem.titleView = customTitleView;
[customTitleView release];
you can add a label in your title bar and then on that label you can show your title and your long string both.
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[titleLabel setBackgroundColor:[UIColor clearColor]];
// here's where you can customize the font size
[titleLabel setFont:[UIFont boldSystemFontOfSize:16.0]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setText:#"hello\nhii"];
[titleLabel setNumberOfLines:2];
[titleLabel setLineBreakMode:UILineBreakModeTailTruncation];
[titleLabel sizeToFit];
[titleLabel setCenter:[self.navigationItem.titleView center]];
[self.navigationItem setTitleView:titleLabel];
[titleLabel release];