自己对于instancetype的理解和应用iOS开发的过程
2015-11-23 00:55
357 查看
- (instancetype)initWithCourse:(TTCourse *)aCourse type:(TTCourseCellType)aType
{
self = [super
init];//这里是必须要写的对于重写init方法来说,开头就是这么写的不能忘记。
if (self !=
nil)
{
self.course = aCourse;
self.clipsToBounds =
YES;
//
封面图
self.coverImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(15, 15, 60 , 60)];
[self.coverImageView
sd_setImageWithURL:[NSURL
URLWithString:self.course.coverURL]
placeholderImage:[UIImage
imageNamed:@"album_holder"]];
/**
* 圆角从2改成3
*/
self.coverImageView.layer.cornerRadius
= 3.0f;
[self.contentView
addSubview:self.coverImageView];
//
曲目名字
self.titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(90, 17, 200, 21)];
self.titleLabel.text =
self.course.title;
self.titleLabel.font =
TTCommonFont(20);
/**
* 设置字体的风格
*/
[self.contentView
addSubview:self.titleLabel];
//
作者
self.authorLabel = [[UILabel
alloc] initWithFrame:CGRectMake(90, 44, 200, 15)];
self.authorLabel.text =
self.course.artist;
self.authorLabel.font =
TTCommonFont(12);
[self.contentView
addSubview:self.authorLabel];
//
难度
self.difficultyLabel = [[UILabel
alloc] initWithFrame:CGRectMake(140, 100, 200, 20)];
self.difficultyLabel.font =
TTCommonFont(14);
CGSize textSize = [self.difficultyLabel.text
sizeWithAttributes:@{NSFontAttributeName :
self.difficultyLabel.font}];
/**
* 72
*/
for (int i = 0; i < 5; i++)
{
UIImage* image = i <
self.course.difficulty.intValue ? [UIImage
imageNamed:@"icon-difficulty-active@3x.png"] : [UIImage
imageNamed:@"icon-difficulty-default@3x.png"];
UIImageView* iv = [[UIImageView
alloc] initWithImage:image];
CGPoint center =
self.difficultyLabel.center;
center.x += (textSize.width / 2 + i * 10)-146;
center.y=72.0;
iv.center = center;
[self.contentView
addSubview:iv];
}
switch (aType) {
case
ECourseTypePractice:
// 加入进度标识
self.progressView = [[MLVCircularProgressView
alloc] initWithFrame:CGRectMake(SYSTEM_SCREEN_WIDTH - 44, 30, 25,
25)];
self.progressView.center =
self.downloadButton.center;
self.progressView.shapeColor = [UIColor
colorWithHexString:@"#cbbcad"];
self.progressView.hidden =
YES;
[self.contentView
addSubview:self.progressView];
break;
case
ECourseTypeFavorite:
// 加入下载按钮
self.downloadButton = [UIButton
buttonWithType:UIButtonTypeCustom];
[self.downloadButton
setImage:[UIImage
imageNamed:@"me_download_button"]
forState:UIControlStateNormal];
self.downloadButton.frame =
CGRectMake(SYSTEM_SCREEN_WIDTH - 44, 30, 44, 44);
[self.downloadButton
addTarget:self
action:@selector(downloadAction:)
forControlEvents:UIControlEventTouchUpInside];
self.downloadButton.hidden =
YES;
[self.contentView
addSubview:self.downloadButton];
break;
case
ECourseTypeCommentAndLike:
// 加入点赞和评论
break;
default:
break;
}
}
return
self;
}
这是对于自己的一个tableviewcell的自定义,这个重新写了init的方法,可以返回自己想要的产生的类型。
至于和id的区别还没有研究。id好像最终不能返回你想要的那个类。。。后续会补充
{
self = [super
init];//这里是必须要写的对于重写init方法来说,开头就是这么写的不能忘记。
if (self !=
nil)
{
self.course = aCourse;
self.clipsToBounds =
YES;
//
封面图
self.coverImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(15, 15, 60 , 60)];
[self.coverImageView
sd_setImageWithURL:[NSURL
URLWithString:self.course.coverURL]
placeholderImage:[UIImage
imageNamed:@"album_holder"]];
/**
* 圆角从2改成3
*/
self.coverImageView.layer.cornerRadius
= 3.0f;
[self.contentView
addSubview:self.coverImageView];
//
曲目名字
self.titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(90, 17, 200, 21)];
self.titleLabel.text =
self.course.title;
self.titleLabel.font =
TTCommonFont(20);
/**
* 设置字体的风格
*/
[self.contentView
addSubview:self.titleLabel];
//
作者
self.authorLabel = [[UILabel
alloc] initWithFrame:CGRectMake(90, 44, 200, 15)];
self.authorLabel.text =
self.course.artist;
self.authorLabel.font =
TTCommonFont(12);
[self.contentView
addSubview:self.authorLabel];
//
难度
self.difficultyLabel = [[UILabel
alloc] initWithFrame:CGRectMake(140, 100, 200, 20)];
self.difficultyLabel.font =
TTCommonFont(14);
CGSize textSize = [self.difficultyLabel.text
sizeWithAttributes:@{NSFontAttributeName :
self.difficultyLabel.font}];
/**
* 72
*/
for (int i = 0; i < 5; i++)
{
UIImage* image = i <
self.course.difficulty.intValue ? [UIImage
imageNamed:@"icon-difficulty-active@3x.png"] : [UIImage
imageNamed:@"icon-difficulty-default@3x.png"];
UIImageView* iv = [[UIImageView
alloc] initWithImage:image];
CGPoint center =
self.difficultyLabel.center;
center.x += (textSize.width / 2 + i * 10)-146;
center.y=72.0;
iv.center = center;
[self.contentView
addSubview:iv];
}
switch (aType) {
case
ECourseTypePractice:
// 加入进度标识
self.progressView = [[MLVCircularProgressView
alloc] initWithFrame:CGRectMake(SYSTEM_SCREEN_WIDTH - 44, 30, 25,
25)];
self.progressView.center =
self.downloadButton.center;
self.progressView.shapeColor = [UIColor
colorWithHexString:@"#cbbcad"];
self.progressView.hidden =
YES;
[self.contentView
addSubview:self.progressView];
break;
case
ECourseTypeFavorite:
// 加入下载按钮
self.downloadButton = [UIButton
buttonWithType:UIButtonTypeCustom];
[self.downloadButton
setImage:[UIImage
imageNamed:@"me_download_button"]
forState:UIControlStateNormal];
self.downloadButton.frame =
CGRectMake(SYSTEM_SCREEN_WIDTH - 44, 30, 44, 44);
[self.downloadButton
addTarget:self
action:@selector(downloadAction:)
forControlEvents:UIControlEventTouchUpInside];
self.downloadButton.hidden =
YES;
[self.contentView
addSubview:self.downloadButton];
break;
case
ECourseTypeCommentAndLike:
// 加入点赞和评论
break;
default:
break;
}
}
return
self;
}
这是对于自己的一个tableviewcell的自定义,这个重新写了init的方法,可以返回自己想要的产生的类型。
至于和id的区别还没有研究。id好像最终不能返回你想要的那个类。。。后续会补充
相关文章推荐
- ios 集成环信的坑
- iOS之[多线程:GCD:Dispatch]
- iOS之[多线程:NSThread]
- iOS之[多线程:NSOperation]
- iostat命令详解
- iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
- iOS之nib、xib及storyboard的区别及storyboard的加载过程
- 蓝懿ios 技术内容交流和学习心得 11.22
- NSString的详细用法(函数说明)
- 开始iOS 7中自动布局教程(一) 从iOS6讲到iOS7以后
- iOS9下使用FMDB出现Undefined symbols for architecture i386: "_NSFileTypeForHFSTypeCode",
- iOS开发之.a文件的制作
- 【iOS】删除 main.storyboard 的问题
- 【iOS】通讯录分组方式展示数据
- iOS 百度定位实现
- iOS 事件传递流程
- iOS 获得汉字拼音首字母
- iOS AFNetworking
- iOS 保持界面流畅的技巧
- iOS的二维码扫描