How to change the navigation bar style in Three20 TTThumbsviewcontroller in iphone? - iphone

I am using Three20 to create a thumbnail view. I want to change the navigation bar style to black from black translucent. If I give blacktranslucent it works fine, if I change it the thumb nail view is lowered like this image.
How can I change it?

You can override the init method, and change whatever you want there. For instance :
// MyThumbsController inherits from TTThumbsViewController
#implementation MyThumbsController
...
- (void) setCustomNavigationBar
{
// Navigation bar logo
UIImage *barLogo = [UIImage imageNamed:#"bar-logo.png"];
UIImageView *barLogoView = [[UIImageView alloc] initWithImage:barLogo];
self.navigationItem.titleView = barLogoView;
// Navigation bar color
self.navigationBarTintColor = HEXCOLOR(0xb22929);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Customization
self.hidesBottomBarWhenPushed = NO;
[self setCustomNavigationBar];
}
return self;
}

Related

navigation controller not showing titles for tabs

I have created a navigationController. In the OnButtonTap action I am adding a tabBarController to navigationController. Now I want the title of every tab on navigationItemBar. But when I change the title in the viewDidLoad method of viewControllers of tab-bar it won't change.
I tried this in viewDidLoad method of view controller in tab bars.
self.title = #"Friends";
self.navigationItem.title=#"Friends";
[self.navigationItem setHidesBackButton:YES];
and the button is also not hiding...
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title=#"YourTitle";
// Custom initialization
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"selectedImage"]withFinishedUnselectedImage:[UIImage imageNamed:#"unselectedImage"]];
}
return self;
}

XIB is not showing / loading the scrollview but the controls added via code inside the viewdidload being shown

I have addded UIScrollView to my xib but it was not showing on to my view controller.
Also in the view did load method, I have added text boxes to the view controller. This is displayed when I push the view, but not the scrollview which I added inside the xib.
I tried to push the view in two ways
Way 1
SubscribedDetailedViewController *aDetailView = [[[SubscribedDetailedViewController alloc]initWithNibName:#"SubscribedDetailedViewController" bundle:nil]autorelease];
[self.navigationController pushViewController:aPoemDetailView animated:YES];
Way 2
SubscribedDetailedViewController *aDetailView = [[[SubscribedDetailedViewController alloc]init]autorelease];
[self.navigationController pushViewController:aPoemDetailView animated:YES];
Also I placed the below code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
The above function also gets called.
Why the scrollview which I added into the xib is not being displayed? But the controls added via code inside the viewdidload being shown.

issue changing UIToolbar tintColor

I have the following code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
webControlsToolbar_ = [[UIToolbar alloc] init];
[self.webControlsToolbar_ setTintColor:[UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1]];
Any idea why the color is still solid black? In my view did load I added the toolbar:
self.webControlsToolbar_.frame = CGRectMake(0, self.view.frameHeight - self.webControlsToolbar_.frameHeight + 1.0, self.view.frameWidth, self.webControlsToolbar_.frameHeight);
[self.view addSubview:self.webControlsToolbar_];
I've run into a similar problem before. I resolved it by setting the tint color immediately before showing the toolbar in code. See if that works for you.
I find it easier to set the background color of a button, label, etc. exactly as I want with the utility bar, then create an outlet called say, myOutlet, and do this:
[self.webControlsToolbar_ setTintColor:myOutlet.backgroundColor];
The issue is at the line
self.webControlsToolbar_.frame = CGRectMake(0, self.view.frameHeight - self.webControlsToolbar_.frameHeight + 1.0, self.view.frameWidth, self.webControlsToolbar_.frameHeight);
Try to NSLog a self.webControlsToolbar_.frameHeight property and you should see that is zero after [UIToolBar new]; Use a constant height instead.
You have to change this attribute in the viewDidLoad method:
-(void)viewDidLoad{
[super viewDidLoad];
//Custom initialization
[self.webControlsToolbar_ setTintColor:[UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1]];
}

Show UIWebView inside UINavigationController on a Modal view without NIB

I have a requirement to load a UIWebView wrapped inside a UINavigationController, and show it on a modal view. UINavigationController should show the navigation bar at the top with a 'back' (I did not find back button, so I used 'done' button). I am not supposed to use a nib, so I have to do it programmatically only. The code has to basically serve as a library which can be integrated with any application. It has to work for IPhone and IPad, both.
This is what I have done so far:
I created a WebViewController class -
#interface WebViewController : UIViewController
{
UIWebView *m_cWebView;
}
#property (nonatomic, retain) UIWebView *m_cWebView;
#end
- (void)loadView
{
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.size.height -= self.navigationController.navigationBar.frame.size.height;
UIWebView *pWebView = [[UIWebView alloc] initWithFrame:webFrame];
pWebView.autoresizesSubviews = YES;
pWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
self.view = pWebView;
pWebView.scalesPageToFit = YES;
self.m_cWebView = pWebView;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(back:)];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if( m_cWebView != nil )
{
NSURL *url = [NSURL URLWithString:#"http://www.google.co.in"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[m_cWebView loadRequest:request];
}
}
- (IBAction)back:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return nil;
}
- (id)init
{
return self;
}
In the main view controller
#property (retain, atomic) UINavigationController *navCon;
-(IBAction)buttonPressed:(id)sender
{
if( navCon == nil )
{
WebViewController* webViewController = [[WebViewController alloc] init];
navCon = [[UINavigationController alloc] initWithRootViewController:webViewController];
}
[self presentModalViewController:navCon animated:YES];
}
So far, it is working fine. Now my issues:
I am totally new to iOS world. Is the above code correct or are there issues?
Code is supposed to be compiled with Xcode 4.2 with ARC, so I presume that I don't need to worry about memory.
Is the logic to calculate the initial size of WebView correct (I am taking the size of main screen and deducting the height of navigation bar)?
How do I handle orientation change such that on changing the orientation, my Navigation View and WebView both adjust to the new orientation?
Thanks
Edit:
I tried implementing with the rotation, but I have not been able to get it to work. willRotateToInterfaceOrientation is not getting called on my WebViewController, even though I am returning YES from shouldAutorotateToInterfaceOrientation ( and this method is getting called ). When I tried working with an empty nib ( loading WebViewController with this empty nib ), then it works fine.
Adding the 5th requirement:
One more additional requirement is that when this modal dialog dismisses, the view which presented this, should be in correct orientation (i.e. while the modal dialog is up, the orientation events are also passed on to the view which presented this modal view).
Thanks
Some points from my side.
Regarding back button, in place of done:
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
Height of navigation bar is always 44.0f
You can handle orientation change with these methods:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation]; // adjust your view frames here
}
I am not sure about your code and memory issues in that - so i could not comment over those.
Hope this information would be helpful to you.
I found the fix to the rotation problem.
Replace
- (id)init
{
return self;
}
with
- (id)init
{
if (self = [super init])
return self;
return nil;
}
and completely remove the following method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return nil;
}
Silly mistakes :)
Now it is rotating fine.
Can someone still comments on the original requirements?

Loading a view into a UIScrollView AND getting the content inside to work

I have a tab based application I am working on.
I have a view controller named DetailsView.m, with an accompanying nib file called DetailsView.xib. This has a couple of UILabels in, which are linked using IBOutlet to DetailsView.m view controller. When I load this view controller/view using the tab bar controller, it works fine and the UILabels are populated dynamically.
Now I want to load this entire view inside a UIScrollView instead so I can fit more content in.
So I created another view controller called DetailsHolder.m with a nib file called DetailsHolder.xib, and assigned this to the tab bar controller.
I wrote this code below to load the first view (DetailsView) into the UIScrollView in the second view (DetailsHolder). I wrote it in the viewDidLoad method of DetailsHolder:
DetailsView* detailsView = [[DetailsView alloc] initWithNibName:#"DetailsView" bundle: nil];
CGRect rect = detailsView.view.frame;
CGSize size = rect.size;
[scrollView addSubview: detailsView.view];
scrollView.contentSize = CGSizeMake(320, size.height);
This correctly loads the sub view into the UIScrollView, however, the labels inside DetailsView no longer do anything. When I put an NSLog inside viewDidLoad of DetailsView - it never logs anything. It's as if I've loaded the nib ok, but its no longer associated with the view controller anymore. What am I missing here? I'm a bit of a newbie in obj C/iOS (but have many years Actionscript/Javascript knowledge.
Thanks in advance,
Rich
Edit: Contents of DetailsView as requested:
DetailsView.h:
#import <UIKit/UIKit.h>
#import "AppModel.h"
#interface DetailsView : UIViewController {
IBOutlet UITextView* textView;
IBOutlet UIImageView* imageView;
}
#end
DetailsView.m
#import "DetailsView.h"
#implementation DetailsView
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
AppModel* model = [AppModel sharedInstance];
[model loadData];
int selectedLocation = [model getSelectedLocation];
NSArray *locations = [model getLocations];
NSArray *data = [locations objectAtIndex:selectedLocation];
textView.text = [data objectAtIndex: 0];
UIImage *theImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[data objectAtIndex: 4] ofType:#"jpg"]];
imageView.image = theImage;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Essentially all its doing is grabbing selectedLocation (int) from a singleton (which is my model), then grabbing an array from the model, and then trying to insert an image and some text into my view. In my nib file, i have a UIImageView and a UITextView, which I have linked to the two IBOutlets declared in DetailsView.h
When you use the view controller like this, many events will not occur in the view controller, e.g. viewWillAppear, viewWillDisappear and device rotation event. My best guess that you did some initialisation in some of those event methods. Posting your code for DetailsView would make it easier to find the problem.