S

ScioLive

 

SDCycleScrollView -> SDCollectionViewCell.m

// // SDCollectionViewCell.m // SDCycleScrollView // // Created by aier on 15-3-22. // Copyright (c) 2015年 GSD. All rights reserved. //

/*


*

*/

#import "SDCollectionViewCell.h" #import "UIView+SDExtension.h"

@implementation SDCollectionViewCell { _weak UILabel *_titleLabel; UIView *bgView;

}

  • (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setupImageView]; [self setupTitleLabel]; }

    return self; }

  • (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor { _titleLabelBackgroundColor = titleLabelBackgroundColor; _titleLabel.backgroundColor = titleLabelBackgroundColor; }

  • (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor { _titleLabelTextColor = titleLabelTextColor; _titleLabel.textColor = titleLabelTextColor; }

  • (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont { _titleLabelTextFont = titleLabelTextFont; _titleLabel.font = titleLabelTextFont; }

  • (void)setupImageView { UIImageView *imageView = [[UIImageView alloc] init]; _imageView = imageView; [self.contentView addSubview:imageView]; }

  • (void)setupTitleLabel { UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.numberOfLines = 2; _titleLabel = titleLabel; _titleLabel.hidden = YES; [self.contentView addSubview:titleLabel]; }

  • (void)setTitle:(NSString *)title { title = [title copy]; _titleLabel.text = [NSString stringWithFormat:@" %@", title]; if (titleLabel.hidden) { _titleLabel.hidden = NO; } }

-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment { _titleLabelTextAlignment = titleLabelTextAlignment; _titleLabel.textAlignment = titleLabelTextAlignment; }

  • (void)layoutSubviews { [super layoutSubviews];

    if (self.onlyDisplayText) { titleLabel.frame = self.bounds; } else { _imageView.frame = self.bounds; CGFloat titleLabelW = self.sd_width; CGFloat titleLabelH = _titleLabelHeight; CGFloat titleLabelX = 10; CGFloat titleLabelY = self.sdheight - titleLabelH-20; _titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW-2*titleLabelX, titleLabelH); [self setupTitleBgView]; } }

  • (void)setupTitleBgView { bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.sd_y, [UIScreen mainScreen].bounds.size.width, _titleLabel.sd_height + 20)]; _bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3]; [self.contentView addSubview:bgView]; [self.contentView insertSubview:_bgView atIndex:1]; } @end