ESFramework Demo之iPhone版--登录

转自:http://www.cnblogs.com/upwifi/archive/2011/08/26/2154750.html

目标:绘制UI完成登录功能

登录界面如下:

1.新建项目 项目名称:RapidEngineDemo

得到项目如下:

2 对所得到的项目做些修改

  1)删掉 MainWindow.xib

      2)编辑 RapidEngineDemo-Info.plist 删掉标签        

           <key>NSMainNibFile</key>

<string>MainWindow</string>

      3)修改main.m 

    #import <UIKit/UIKit.h>

 

      int main(int argc, char *argv[]) {

    

          NSAutoreleasePool * pool = [[NSAutoreleasePool allocinit];

          int retVal = UIApplicationMain(argc, argv, nil,  @"RapidEngineDemoAppDelegate");

          [pool release];

          return retVal;

      }

       成为这个样子

 

     4)修改RapidEngineDemoAppDelegate.h 和 RapidEngineDemoAppDelegate.m 
 
        RapidEngineDemoAppDelegate.h

    #import <UIKit/UIKit.h>

 

    @interface RapidEngineDemoAppDelegate : NSObject <UIApplicationDelegate> {

    

         UIWindowwindow;

  UITabBarControllertabController;

 

    }

 

 

    @property (nonatomicretain) UITabBarController* tabController;

 

 

 

    @end

 
         RapidEngineDemoAppDelegate.m

    #import "RapidEngineDemoAppDelegate.h"

    #import "RootViewController.h"

    #import "CustomUINavigationController.h"

 

    @implementation RapidEngineDemoAppDelegate

 

    @synthesize tabController;

 

 

    #pragma mark -

    #pragma mark Application lifecycle

 

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    

        // Override point for customization after application launch.

    

        // Add the navigation controller's view to the window and display.

 

 

   window = [[UIWindow allocinitWithFrame:[[UIScreen  mainScreenbounds]];

   tabController = [[CustomUINavigationController allocinit];

 

  [tabController setViewControllers:

         [NSArray arrayWithObjects:

    [[[UINavigationController allocinitWithRootViewController:[[[RootViewController allocinitWithTabBarItemTitle:@"RapidDemo" iconName:@"Messages.png" tag:0]autorelease]] autorelease],

    nil]];

 

  [window addSubview:[tabController view]];

 

 

  [window makeKeyAndVisible];

 

        return YES;

    }

   
        5)填加RootViewController.h 和 RootViewController.m
 

    #import <UIKit/UIKit.h>

 

    @interface RootViewController : UITableViewController {

 

    }

 

    - (id)initWithTabBarItemTitle:(NSString *)title iconName:(NSString *)iconName tag:(NSInteger)tag;

 

    @end

 

    RootViewController.m 这里要标注一下 initWithStyle:UITableViewStyleGrouped是设置UITable的样式      

 

 

    - (id)initWithTabBarItemTitle:(NSString *)title iconName:(NSString *)iconName tag:(NSInteger)tag{

if (self = [super initWithStyle:UITableViewStyleGrouped]) {

self.title = title;

self.tableView.scrollEnabled = NO;

UIImage *icon = [UIImage imageNamed:iconName];

UITabBarItem *item = [[UITabBarItem allocinitWithTitle:title image:icon tag:tag];

self.tabBarItem = item;

[item release];

}

return self;

    }

 

 

    // Customize the number of sections in the table view.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

        return 1;

    }

 

 

    // Customize the number of rows in the table view.

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

        return 2;

    }

 
         表格中的cell要自己绘制的 

 

    // Customize the appearance of table view cells.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

static NSString *CellIdentifier = @"Cell";

    

       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 

//AppDelegate* appData = [[UIApplication sharedApplication] delegate];

if ([indexPath row] == 0) {

CellIdentifier = @"UserNameCell";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell = [[[CellWithTextField allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

((CellWithTextField *)cell).lbl.text = @"昵称:";

 

((CellWithTextField *)cell).lbl.backgroundColor = [UIColor clearColor];

((CellWithTextField *)cell).lbl.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];

 

 

 

}else if ([indexPath row] == 1) {

 

CellIdentifier = @"PasswordCell";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 

cell = [[[CellWithTextField allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

 

((CellWithTextField *)cell).lbl.text = @":";

 

((CellWithTextField *)cell).lbl.backgroundColor = [UIColor clearColor];

((CellWithTextField *)cell).lbl.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];

 

 

}

 

        return cell;

    }

 

         6)填加CellWithTextField.h 和 CellWithTextField.m
 

    #import <Foundation/Foundation.h>

 

 

    @interface CellWithTextField : UITableViewCell {

  UILabel *lbl;

  UITextField *txt;

    }

 

    @property(nonatomic,retain)UILabel *lbl;

    @property(nonatomic,retain)UITextField *txt; 

    @end

 

 

    #import "CellWithTextField.h"

 

 

    @implementation CellWithTextField

    @synthesize lbl,txt;

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

        if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            // Initialization code

self.selectionStyle = UITableViewCellSelectionStyleNone

 

self.lbl = [[UILabel allocinitWithFrame:CGRectZero];

[self.contentView addSubview:self.lbl];

[self.lbl release];

 

self.txt = [[UITextField allocinitWithFrame:CGRectZero];

self.txt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

[self.contentView addSubview:self.txt];

[self.txt release];

 

        }

        return self;

    }

 

    -(void)layoutSubviews{

  [super layoutSubviews];

  float inset = 5.0;

  CGRect bounds = [[self contentViewbounds];

  float h = bounds.size.height

  float w = bounds.size.width

  CGSize label_text_size = [self.lbl.text sizeWithFont:self.lbl.font];

  float labelWidth = label_text_size.width;

 

 

 

  CGRect innerFrame = CGRectMake(inset, inset, labelWidth, h-inset*2);

  [lbl setFrame:innerFrame];

 

  innerFrame.origin.x += innerFrame.size.width+inset;

  innerFrame.size.width = w - (labelWidth+inset*3);

  [txt setFrame:innerFrame];

    }

 

 

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {

 

        [super setSelected:selected animated:animated];

 

        // Configure the view for the selected state

    }

 

 

    - (void)dealloc {

    

  [lbl release];

  [txt release];

  [super dealloc];

    }

 

 

    @end

 
       需要此版本的项目源码请点此处下载
posted @ 2013-04-25 09:35  ADTL  阅读(113)  评论(0)    收藏  举报