addressBookHelpercell的定制
来源:互联网 发布:安全气囊碰撞数据 编辑:程序博客网 时间:2024/06/01 07:53
@protocol AddressBookCellDelegate <NSObject>- (void)didClickCallButtonAtIndexPath:(NSIndexPath *)indexPath;@end@interface AddressBookCell : UITableViewCell@property (nonatomic, retain) UIImageView *photoView;@property (nonatomic, retain) UILabel *nameLabel;@property (nonatomic, retain) UILabel *phoneNumberLabel;@property (nonatomic, retain) UIButton *callButton;@property (nonatomic, retain) NSIndexPath *indexPath;//存储cell的位置@property (nonatomic, retain) AddressPerson *person; //存储数据源对象@property (nonatomic, assign) id<AddressBookCellDelegate> delegate;@end<pre name="code" class="objc">@implementation AddressBookCell//重写setPerson方法,给对应的控件赋值.- (void)setPerson:(AddressPerson *)person{ if (_person != person) { [_person release]; _person = [person retain]; } //给对应的控件赋值 self.photoView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:person.imageName ofType:@"png"]]; self.nameLabel.text = person.name; self.phoneNumberLabel.text = person.phoneNumber;}- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code //photoView CGFloat px = kPhotoView_MarginLeft; CGFloat py = kPhotoView_MarginTop; CGFloat width = kPhotoView_Width; CGFloat height = kPhotoView_Height; self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(px, py, width, height)]; /** * 1.新建一个CAShaperLayer 对象 2.新建一个UIBezierPath 对象 3.绘制贝塞尔曲线路径 4.将贝塞尔曲线路径赋值给layer. 5.然后将该layer对象添加到一个视图的layer上. */ CAShapeLayer *layer = [CAShapeLayer layer]; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.photoView.bounds cornerRadius:kCornerRadius]; layer.frame = _photoView.bounds; layer.path = bezierPath.CGPath; _photoView.layer.mask = layer;// _photoView.layer.cornerRadius = kCornerRadius;// _photoView.layer.masksToBounds = YES; [self.contentView addSubview:_photoView]; [_photoView release]; //nameLabel px = px + width + kMarginBetween; py = kMarginTop; width = kNameLabel_Width; height = kHeight; self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_nameLabel]; [_nameLabel release]; //phoneNumberLabel px = px + width; py = py; width = kPhoneNumberLabel_Width; height = height; self.phoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; _phoneNumberLabel.textAlignment = NSTextAlignmentCenter; _phoneNumberLabel.font = [UIFont systemFontOfSize:15]; _phoneNumberLabel.textColor = [UIColor lightGrayColor]; [self.contentView addSubview:_phoneNumberLabel]; [_phoneNumberLabel release]; //callButton px = px + width; py = py; width = kCallView_Width; height = height; self.callButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_callButton setImage:[UIImage imageNamed:@"action_call"] forState:UIControlStateNormal]; [_callButton addTarget:self action:@selector(call:) forControlEvents:UIControlEventTouchUpInside]; _callButton.frame = CGRectMake(px, py, width, height); [self.contentView addSubview:_callButton]; } return self;}- (void)call:(UIButton *)btn{ if ([self.delegate respondsToSelector:@selector(didClickCallButtonAtIndexPath:)]) { [self.delegate didClickCallButtonAtIndexPath:self.indexPath]; }}- (void)awakeFromNib{ // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; // Configure the view for the selected state}- (void)dealloc{ RELEASE_SAFE(_indexPath); RELEASE_SAFE(_photoView); RELEASE_SAFE(_nameLabel); RELEASE_SAFE(_phoneNumberLabel); RELEASE_SAFE(_callButton); [super dealloc];}@end
0 0
- addressBookHelpercell的定制
- 定制DataGrid的风格
- 流程定制的小结
- 定制DataGrid的外观
- 定制DataGrid的外观
- 定制自己的linux
- google定制的搜索引擎
- 创建定制的组件
- 定制您的 Shell
- OnFileNew()的定制
- 关于OnFileNew()的定制
- 定制Row的不同颜色
- VMR9的定制AP
- DXUTGUI控件的定制
- VMR9的定制AP
- 定制自己的DataGridView
- vim的定制
- iNotes的定制
- 分享一个连接
- centos6.3 下mysql5.5 中文乱码
- nyoj28大数阶乘
- 个人写的分割正整数方法
- 质因数分解
- addressBookHelpercell的定制
- nyoj28大数阶乘
- 线程同步控制的几种方式
- 阿里巴巴之孕育、裂变及归因
- dll加载问题的解决方法
- 腾讯2014实习生招聘经历谈
- 通讯录图库界面,两种cell的定制
- 在控制台中动态引入jquery的方法
- C++ Map快速入门