当前位置:  编程技术>移动开发
本页文章导读:
    ▪手机施用推广-转载        手机应用推广-转载 手机应用推广 ......
    ▪ 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.
 - (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!




    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
c/c++开源软件 iis7站长之家
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3