zoukankan      html  css  js  c++  java
  • ESFramework Demo之iPhone版登录

    目标:绘制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 alloc] init];

              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> {

        

             UIWindow* window;

      UITabBarController* tabController;

        }

        @property (nonatomic, retain) 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 alloc] initWithFrame:[[UIScreen  mainScreen] bounds]];

       tabController = [[CustomUINavigationController alloc] init];

      [tabController setViewControllers:

             [NSArray arrayWithObjects:

        [[[UINavigationController alloc] initWithRootViewController:[[[RootViewController alloc] initWithTabBarItemTitle:@"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 alloc] initWithTitle: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 alloc] initWithStyle: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 alloc] initWithStyle: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 alloc] initWithFrame:CGRectZero];

    [self.contentView addSubview:self.lbl];

    [self.lbl release];

    self.txt = [[UITextField alloc] initWithFrame: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 contentView] bounds];

      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


           需要此版本的项目源码请点此处下载
  • 相关阅读:
    洛谷P1258小车问题
    洛谷P1028 数的计算
    P1980 计数问题
    洛谷P1907口算练习题
    2018icpc沈阳-K.Let the Flames Begin (约瑟夫环问题)
    Codeforces Round #585 (Div. 2) B. The Number of Products
    字符串部分模板总结
    CF-1209D Cow and Snacks (并查集,图)
    Codeforces Round #584 (div.1+div.2)(补题)
    HDU
  • 原文地址:https://www.cnblogs.com/upwifi/p/2154750.html
Copyright © 2011-2022 走看看