2016-03-04 一个完整的model 样式

1:

#import "ContactListViewCell.h"

 

@implementation ContactListViewCell

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

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

        

        _portraitImg = [[UIImageView alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 45.0f, 45.0f)];

        _portraitImg.contentMode = UIViewContentModeScaleToFill;

        _portraitImg.image = [UIImage imageNamed:@"personal_portrait"];

        [self.contentView addSubview:_portraitImg];

        

        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0f, 10.0f, self.frame.size.width-150.0f, 25.0f)];

        _nameLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;

        [self.contentView addSubview:_nameLabel];

        

        _numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.frame.origin.x, _nameLabel.frame.origin.y+_nameLabel.frame.size.height, _nameLabel.frame.size.width, 15.0f)];

        _numberLabel.font = [UIFont systemFontOfSize:13.0f];

        _numberLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;

        _numberLabel.textColor = [UIColor grayColor];

        [self.contentView addSubview:_numberLabel];

    }

    return self;

}

 

@end

2:

  static NSString *contactlistcellid = @"ContactListViewCellidentifier";

        ContactListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:contactlistcellid];

        if (cell == nil) {

            cell = [[ContactListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contactlistcellid];

        }

        AddressBook *book = addressbook;

        cell.portraitImg.image = book.head;

        cell.nameLabel.text = book.name;

        NSString* phone = [book.phones allValues].firstObject;

        cell.numberLabel.text = phone?phone:@"无号码";

        return cell;

 

 

 

 

3:

#import <Foundation/Foundation.h>

 

@interface AddressBook : NSObject

 

#pragma mark- 通讯录信息

@property (nonatomic, copy) NSString *name;

@property (nonatomic, strong) UIImage *head;

@property (nonatomic, strong) NSMutableDictionary *phones;

@property (nonatomic, strong) NSMutableDictionary *others;

 

/**

 *  名字头字母

 */

@property (nonatomic, readonly) NSString *firstLetter;

 

@end

原文地址:https://www.cnblogs.com/gzz2016/p/5242938.html