当前位置: 编程技术>移动开发
本页文章导读:
▪手机施用推广-转载 手机应用推广-转载
手机应用推广
......
▪ UISplitView的容易示例 UISplitView的简单示例
splitAppDelegate.h
#import <UIKit/UIKit.h>
@class MasterViewController;
@class DetailViewController;
@interface splitAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UISpl.........
▪ UINavigationBar,UIBarButtonItem 相干 UINavigationBar,UIBarButtonItem 相关
1. Adding a Custom UIBarButtonItemWe will use an image in the resources folder called “back.png”. To insert the image as the back button, add this piece of code to the AppDelegate.m file. This should be i.........
[1]手机施用推广-转载
来源: 互联网 发布时间: 2014-02-18
手机应用推广-转载
手机应用推广
[2] UISplitView的容易示例
来源: 互联网 发布时间: 2014-02-18
UISplitView的简单示例
splitAppDelegate.h
#import <UIKit/UIKit.h> @class MasterViewController; @class DetailViewController; @interface splitAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UISplitViewController *splitViewController; MasterViewController *masterViewController; DetailViewController *detailViewController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) UISplitViewController *splitViewController; @property (nonatomic, retain) MasterViewController *masterViewController; @property (nonatomic, retain) DetailViewController *detailViewController; @end
splitAppDelegate.m
#import "splitAppDelegate.h" #import "MasterViewController.h" #import "DetailViewController.h" @implementation splitAppDelegate @synthesize window, splitViewController, masterViewController, detailViewController; #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; masterViewController.detailViewController = detailViewController; splitViewController = [[UISplitViewController alloc] init]; splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil]; splitViewController.delegate = detailViewController; [masterViewController release]; [detailViewController release]; [navigationController release]; [window addSubview:splitViewController.view]; [window makeKeyAndVisible]; return YES; } #pragma mark - #pragma mark Memory management - (void)dealloc { [splitViewController release]; [window release]; [super dealloc]; } @end
MasterViewController.h
#import <UIKit/UIKit.h> @class DetailViewController; @interface MasterViewController : UITableViewController { DetailViewController *detailViewController; NSMutableArray * fruits; } @property (nonatomic, retain) IBOutlet DetailViewController *detailViewController; @property (nonatomic, retain) NSMutableArray *fruits; @end
MasterViewController.m
#import "MasterViewController.h" #import "DetailViewController.h" @implementation MasterViewController @synthesize detailViewController; @synthesize fruits; #pragma mark - #pragma mark Size for popover - (CGSize)contentSizeForViewInPopoverView { return CGSizeMake(200.0, 400.0); } #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.fruits = [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fruits" ofType:@"plist"]] retain]; } #pragma mark - #pragma mark Table view data source - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { return [fruits count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; } cell.textLabel.text = [self.fruits objectAtIndex:indexPath.row]; return cell; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { detailViewController.detailItem = [self.fruits objectAtIndex: indexPath.row]; } #pragma mark - #pragma mark Memory management - (void)dealloc { [detailViewController release]; [super dealloc]; } @end
DetailViewController.h
#import <UIKit/UIKit.h> @interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> { UIPopoverController *popoverController; UINavigationBar *navigationBar; id detailItem; IBOutlet UIImageView *fruitImageView; } @property (nonatomic, retain) UIPopoverController *popoverController; @property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar; @property (nonatomic, retain) id detailItem; @property (nonatomic, retain) IBOutlet UIImageView *fruitImageView; @end
DetailViewController.m
#import "DetailViewController.h" #import "MasterViewController.h" @implementation DetailViewController @synthesize navigationBar, popoverController, detailItem,fruitImageView; #pragma mark - #pragma mark Managing the popover controller - (void)setDetailItem:(id)newDetailItem { if (detailItem != newDetailItem) { [detailItem release]; detailItem = [newDetailItem retain]; navigationBar.topItem.title = detailItem; NSString * imageName = [NSString stringWithFormat:@"%@.png",detailItem]; [self.fruitImageView setImage:[UIImage imageNamed:imageName]]; } if (popoverController != nil) { [popoverController dismissPopoverAnimated:YES]; } } #pragma mark - #pragma mark Split view support - (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc { barButtonItem.title = @"Master List"; [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES]; self.popoverController = pc; } - (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { self.popoverController = nil; } - (void)viewDidUnload { self.popoverController = nil; } #pragma mark - #pragma mark Memory management - (void)dealloc { [popoverController release]; [navigationBar release]; [detailItem release]; [super dealloc]; } @end
示例图:
[3] UINavigationBar,UIBarButtonItem 相干
来源: 互联网 发布时间: 2014-02-18
UINavigationBar,UIBarButtonItem 相关
1. Adding a Custom UIBarButtonItem
We will use an image in the resources folder called “back.png”. To insert the image as the back button, add this piece of code to the AppDelegate.m file. This should be in the application:didFinishLaunchingWihOptions method.
2. A Simple Way to Animate a UIBarButtonItem
My first pass solution to animate a UIBarButtonItem was to initialize it's custom view with a UIImageView. The UIImageView can then be set up for animation with multiple images. Calling startAnimaiton/stopAnimation on the UIImaveView will then animate. This is great for animating buttons in tool and tab bars.
One problem is that the when initializing the UIImageView into the UIBarButtonItem, the UIBarButtonItem does not respond to touch events. Yuk.
A simple solution is to initialize the UIBarButtonItem custom view with a UIButton, then touch events for the UIBarButtonItem item are handle correctly.
But the UIButton does not have a way to use a UIImageView only UIImages. We want to use the UIImageView for its simple animation.
The solution is to add the UIImageView as a subview of the UIButton.
Here is the code.
Some things to notice:
The UIButton is of zero area as it does not have its bounds set upon initialization, thus the bounds are initialized with the bounds of the UIImageView (which has its bounds initialized from the image).
The UIButton handles the action/target for the touch event. The UIBarButtonItem's action/target are not set.
To animate:
[imageView startAnimating];
Have fun,
Sean
===========================================
As you know, until iOS 5 came out, we used drawRect override in AppDelegate to customize UINavigationBar. But know, iOS 5 give us some new method for styling (and old doesn’t work).
How to build app that will work on iOS 4 and iOS 5 with stylized UINavigationBar?
You must to do both!
In AppDelegate use this code:
and in viewDidLoad method for iOS5 (in your view implementation):
If you see, here we are asking if navbar will respondToSelector to avoid crash on iOS4!
1. Adding a Custom UIBarButtonItem
We will use an image in the resources folder called “back.png”. To insert the image as the back button, add this piece of code to the AppDelegate.m file. This should be in the application:didFinishLaunchingWihOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIImage *navBarImage = [UIImage imageNamed:@"menubar.png"]; [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; UIImage* backButtonImage = [UIImage imageNamed:@"back.png"]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; return YES; }
2. A Simple Way to Animate a UIBarButtonItem
My first pass solution to animate a UIBarButtonItem was to initialize it's custom view with a UIImageView. The UIImageView can then be set up for animation with multiple images. Calling startAnimaiton/stopAnimation on the UIImaveView will then animate. This is great for animating buttons in tool and tab bars.
One problem is that the when initializing the UIImageView into the UIBarButtonItem, the UIBarButtonItem does not respond to touch events. Yuk.
A simple solution is to initialize the UIBarButtonItem custom view with a UIButton, then touch events for the UIBarButtonItem item are handle correctly.
But the UIButton does not have a way to use a UIImageView only UIImages. We want to use the UIImageView for its simple animation.
The solution is to add the UIImageView as a subview of the UIButton.
Here is the code.
NSArray *images = [NSArray arrayWithObjects: [UIImage imageNamed:@"image0.png"], [UIImage imageNamed:@"image1.png"], nil]; imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.png"]]; imageView.animationImages = images; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.bounds = self.imageView.bounds; [button addSubview:self.imageView]; [button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithCustomView: button] autorelease];
Some things to notice:
The UIButton is of zero area as it does not have its bounds set upon initialization, thus the bounds are initialized with the bounds of the UIImageView (which has its bounds initialized from the image).
The UIButton handles the action/target for the touch event. The UIBarButtonItem's action/target are not set.
To animate:
[imageView startAnimating];
Have fun,
Sean
===========================================
As you know, until iOS 5 came out, we used drawRect override in AppDelegate to customize UINavigationBar. But know, iOS 5 give us some new method for styling (and old doesn’t work).
How to build app that will work on iOS 4 and iOS 5 with stylized UINavigationBar?
You must to do both!
In AppDelegate use this code:
@implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { UIImage *img = [UIImage imageNamed:@"navbar.png"]; [img drawInRect:rect]; } @end
and in viewDidLoad method for iOS5 (in your view implementation):
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault]; }
If you see, here we are asking if navbar will respondToSelector to avoid crash on iOS4!
最新技术文章: