Share Coding

Tutorials, Problems, Stuffs …

Tag Archives: uiview

Make Background Image Fitting to the UIView

1.             Too Small                                    Too Large                                What we want
Too SmallToo LargeFit

2. To make a centered and stretched image:

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];
Advertisements

Objective C – Basic UIView with navigation controller

This is a changing views solution:

[self presentModalViewController:view animated:YES];

 

In some situations that wanting to use Navigation Controller’s changing page animation effect:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	// IOS 5.x
	self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
	UINavigationController *nvc =[[UINavigationController alloc] initWithRootViewController:viewController];
	nvc.navigationBar.barStyle = UIBarStyleBlack;
	[window addSubview:nvc.view];
	[self.window makeKeyAndVisible];
	return YES;

	/* IOS 4.x
	UINavigationController *nvc =[[UINavigationController alloc] initWithRootViewController:viewController];
	nvc.navigationBar.barStyle = UIBarStyleBlack;
	[window addSubview:nvc.view];
	[self.window makeKeyAndVisible];
	return YES;
	*/
}

 
Read more of this post