iOS通讯录

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


#import "AppDelegate.h"
#import "MainViewController.h"

@implementation AppDelegate
- (void)dealloc
{
    [_window release];
    _window = nil;
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    MainViewController *main = [[MainViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
    [_window setRootViewController:nav];
    [main release];
    [nav release];
    
    [self.window makeKeyAndVisible];
    return YES;
}
SecondViewController.h

#import <UIKit/UIKit.h>
@class Person;
@interface SecondViewController : UIViewController
@property (nonatomic,retain) Person *myPer;
@end
SecondViewController.m
#import "SecondViewController.h"
#import "CustomViewTableViewCell.h"
#import "Person.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor blackColor]];
    self.navigationController.navigationBar.translucent = NO;
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];
    
    [table setBackgroundColor:[UIColor orangeColor]];
    table.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);//分割线上左下右
    table.rowHeight = 100;//行高,默认44的高度
    table.separatorColor = [UIColor magentaColor];
    //    table.separatorStyle = UITableViewCellSeparatorStyleNone;
   
    
    [self.view addSubview:table];
    [table release];
    
   UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(100, 40,120, 120)];
    image.backgroundColor = [UIColor whiteColor];
    [image setImage:[UIImage imageNamed:self.myPer.image]];
    image.layer.borderColor = [UIColor cyanColor].CGColor;
    image.layer.borderWidth = 3;
    image.layer.masksToBounds = YES;
    image.layer.cornerRadius = 60;
    image.userInteractionEnabled = YES;
    
   
    [self.view addSubview:image];
    [image release];
    
    
    UILabel *nameLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 170, 320, 60)];
    
    nameLable.alpha = 0.8;
    [nameLable setText:self.myPer.name];
    [nameLable setTextAlignment:NSTextAlignmentCenter];
    [nameLable setTextColor:[UIColor whiteColor]];
    [nameLable setFont:[UIFont boldSystemFontOfSize:35]];
    
    [nameLable setShadowColor:[UIColor blackColor]];
    [nameLable setShadowOffset:CGSizeMake(1, 1)];
    [self.view addSubview:nameLable];
    [nameLable release];
    
    UILabel *phoneLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 290, 320, 60)];
    [phoneLable setText:self.myPer.phone];
    phoneLable.alpha = 0.8;
    [phoneLable setTextAlignment:NSTextAlignmentCenter];
    [phoneLable setFont:[UIFont boldSystemFontOfSize:35]];
    [phoneLable setTextColor:[UIColor whiteColor]];
        [phoneLable setShadowColor:[UIColor blackColor]];
    [phoneLable setShadowOffset:CGSizeMake(1, 1)];
    [self.view addSubview:phoneLable];
    [phoneLable release];

    UILabel *sexLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 230, 320, 60)];
    [sexLable setText:self.myPer.sex];
    sexLable.alpha = 0.8;
    [sexLable setTextAlignment:NSTextAlignmentCenter];
    [sexLable setFont:[UIFont boldSystemFontOfSize:35]];
    [sexLable setTextColor:[UIColor whiteColor]];
        [sexLable setShadowColor:[UIColor blackColor]];
    [sexLable setShadowOffset:CGSizeMake(1, 1)];
    [self.view addSubview:sexLable];
    [sexLable release];
  
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
MainViewController.h

#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController
{
    NSMutableArray *_tableArray;
}
@end

MainViewController.m

#import "MainViewController.h"
#import "CustomViewTableViewCell.h"
#import "Person.h"
#import "SecondViewController.h"
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation MainViewController
- (void)dealloc
{
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        Person *p1 = [Person personWithimage:@"哈士奇.png" name:@"哈士奇" sex:@"男" phone:@"15345983654"];
        Person *p2 = [Person personWithimage:@"鼻孔.jpg" name:@"鼻孔兄"sex:@"男" phone:@"15345998638"];
        Person *p3 = [Person personWithimage:@"神烦狗.png" name:@"神烦狗"sex:@"男" phone:@"15656940235"];
        Person *p4 = [Person personWithimage:@"33.jpg" name:@"男神"sex:@"男" phone:@"15852596714"];
        Person *p5 = [Person personWithimage:@"7.jpg" name:@"大美妞"sex:@"女" phone:@"18962487563"];
        Person *p6 = [Person personWithimage:@"55.jpg" name:@"Darling"sex:@"男" phone:@"15345985214"];
        Person *p7 = [Person personWithimage:@"10.jpg" name:@"小纯"sex:@"女" phone:@"15125863611"];
        Person *p8 = [Person personWithimage:@"13.png" name:@"女神"sex:@"女" phone:@"15345983654"];
        Person *p9 = [Person personWithimage:@"小黄人.jpg" name:@"小黄人"sex:@"男" phone:@"15345983654"];
        Person *p10 = [Person personWithimage:@"11.png" name:@"Smiling"sex:@"女" phone:@"15345989874"];
        
        _tableArray = [[NSMutableArray alloc] init];
        [_tableArray addObject:p1];
        [_tableArray addObject:p2];
        [_tableArray addObject:p3];
        [_tableArray addObject:p4];
        [_tableArray addObject:p5];
        [_tableArray addObject:p6];
        [_tableArray addObject:p7];
        [_tableArray addObject:p8];
        [_tableArray addObject:p9];
        [_tableArray addObject:p10];
        
        
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];
    [table setBackgroundColor:[UIColor blackColor]];
    table.separatorInset = UIEdgeInsetsMake(0, 80, 0, 100);//分割线上左下右
    table.rowHeight = 80;//
    table.separatorColor = [UIColor blackColor] ;
    table.dataSource = self;
    table.delegate = self;
    
    [self.view addSubview:table];
    [table release];
    
                            
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_tableArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //从重用池里取cell
    static NSString *cellIdentify = @"QQ";
    
    CustomViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[[CustomViewTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"www"] autorelease];
    }
    Person *p = [_tableArray objectAtIndex:indexPath.row];
    [cell.image setImage:[UIImage imageNamed:p.image]];
   
    [cell.nameLable setText:p.name];
    
    
    
    return cell;

}
//实现delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Person *p = [_tableArray objectAtIndex:indexPath.row];
    SecondViewController *second = [[SecondViewController alloc] init];
    second.myPer = p;
    [self.navigationController pushViewController:second animated:YES];
    [second release];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

CustomViewTableViewCell.h
#import <UIKit/UIKit.h>

@interface CustomViewTableViewCell : UITableViewCell
@property (nonatomic,retain) UIImageView *image;
@property (nonatomic,retain) UILabel *nameLable;

@end

#import "CustomViewTableViewCell.h"

@implementation CustomViewTableViewCell
- (void)dealloc
{
    [_image release];
    _image = nil;
    [_nameLable release];
    _nameLable = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.image = [[UIImageView alloc] initWithFrame:CGRectMake(30, 10, 60, 60)];
        _image.backgroundColor = [UIColor whiteColor];
                [_image setImage:[UIImage imageNamed:@"11.png"]];
        _nameLable.layer.borderColor = [UIColor cyanColor].CGColor;
        _nameLable.layer.borderWidth = 6;
        _image.layer.masksToBounds = YES;
        _image.layer.cornerRadius = 30;
        _image.userInteractionEnabled = YES;
        
        //
//        _image.alpha = 2;
        [self.contentView addSubview:_image];
        [_image release];
        
        
        self.nameLable = [[UILabel alloc] initWithFrame:CGRectMake(120, 30, 200, 30)];
//        _nameLable.layer.borderColor = [UIColor grayColor].CGColor;
//        _nameLable.layer.cornerRadius = 30;
//        _nameLable.layer.borderWidth = 30;
        
        [_nameLable setTextColor:[UIColor whiteColor]];
        [_nameLable setTextAlignment:NSTextAlignmentNatural];
        [_nameLable setShadowColor:[UIColor blackColor]];
        [_nameLable setShadowOffset:CGSizeMake(1, 1)];
        [_nameLable setFont:[UIFont boldSystemFontOfSize:23]];
        [self.contentView addSubview:_nameLable];
        [_nameLable release];
        
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        
        
        
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
Person.h
#import <Foundation/Foundation.h>

@interface Person : NSObject

@property (nonatomic,retain) NSString *image;
@property (nonatomic,retain) NSString *name;
@property (nonatomic,retain) NSString *sex;
@property (nonatomic,retain) NSString *phone;


+ (Person *)personWithimage:(NSString *)image name:(NSString *)name sex:(NSString *)sex phone:(NSString *)phone;
@end
Person.m
#import "Person.h"

@implementation Person
- (void)dealloc
{
    [_image release];
    _image = nil;
    [_name release];
    _name = nil;
    [super dealloc];
}

- (id)initWithimage:(NSString *)image name:(NSString *)name sex:(NSString *)sex phone:(NSString *)phone
{
    self = [super init];
    if (self) {
        self.image = image;
        self.name = name;
        self.sex = sex;
        self.phone = phone;
    }
    return self;
}

+ (Person *)personWithimage:(NSString *)image name:(NSString *)name sex:(NSString *)sex phone:(NSString *)phone
{
    Person *p = [[Person alloc] initWithimage:image name:name sex:sex phone:phone];
    return [p autorelease];
}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值