|
//
// TPShareContentController.m
// ThePaperBase
//
// Created by Huixin on 15/8/10.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "TPShareContentController.h"
#import "shareContent.h"
@interface labelButton : UICollectionViewCell
@property(nonatomic, strong)UIButton *btn;
@property(nonatomic, strong)UIImageView *btnImg;
@property(nonatomic, strong)UILabel *label;
@end
@implementation labelButton
- (id)init{
self = [super init];
return self;
}
- (void)initWithTarget:(id)target selector:(SEL)selector text:(NSString*)text{
[self addSubview:self.btn];
[self.btn addSubview:self.btnImg];
[self addSubview:self.label];
[self.btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
self.label.text = text;
[self.btn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top);
make.left.equalTo(self.left);
make.right.equalTo(self.right);
make.height.equalTo(self.width);
}];
[self.btnImg makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@25);
make.height.equalTo(@25);
make.center.equalTo(self.btn.center);
}];
//CGFloat width = widthForString(text, self.label.font, 30, self.label.lineBreakMode);
[self.label makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.btn.bottom).offset(5);
make.left.equalTo(self.left).offset(-15);
make.right.equalTo(self.right).offset(15);
make.bottom.equalTo(self.bottom);
}];
}
- (UIButton*)btn {
if (!_btn) {
_btn = [UIButton buttonWithType:UIButtonTypeCustom];
_btn.backgroundColor = [UIColor clearColor];
[_btn setBackgroundImage:Image(@"login/shareSafari_bg.png") forState:UIControlStateNormal];
[_btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateHighlighted];
[_btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateSelected];
}
return _btn;
}
-(UIImageView *)btnImg{
if (!_btnImg) {
_btnImg = [UIImageView new];
_btnImg.image = Image(@"login/shareSafari.png");
_btnImg.userInteractionEnabled = NO;
}
return _btnImg;
}
- (UILabel*)label {
if (!_label) {
_label = [[UILabel alloc] init];
_label.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_label.textColor = [UIColor colorWithHexString:TextGray];
_label.textAlignment = NSTextAlignmentCenter;
_label.backgroundColor = [UIColor clearColor];
}
return _label;
}
- (void)setNormalImage:(UIImage*)normalImage highlightedImage:(UIImage*)highlightedImage selectedImage:(UIImage*)selectedImage {
[self.btn setImage:normalImage forState:UIControlStateNormal];
if (highlightedImage) {
[self.btn setImage:highlightedImage forState:UIControlStateHighlighted];
}
if (selectedImage) {
[self.btn setImage:selectedImage forState:UIControlStateSelected];
}
}
@end
@interface TPShareContentController()<shareContentDelegate>{
CGFloat iconPadding;
CGFloat iconWidthAndHeight;
CGFloat iconBtnHeight;
CGFloat contentHeight;
CGFloat iconBtnPadding;
}
@property(nonatomic, strong)labelButton *safariBtn;
@property(nonatomic, strong)UILabel *textLabel;
@property(nonatomic, strong)TPCustomButton *cancelBtn;
//@property(nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong) shareContent *shareVC;
@property(nonatomic, strong)UIScrollView *scrollView;//像4S屏幕小的能上下滚动
@end
@implementation TPShareContentController
@synthesize contentBO = _contentBO;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
if (IS_IPHONE_6P) {
iconPadding = 40;
}else if (IS_IPHONE_6){
iconPadding = 43;
}else {
iconPadding = 30;
}
iconWidthAndHeight = (rect_screen.size.width-5*iconPadding)/4;
iconBtnHeight = iconWidthAndHeight + 13/2 + 16;
iconBtnPadding = iconPadding - 13;
contentHeight = 2*iconPadding + iconBtnHeight*3 + iconBtnPadding*2;
//20+61+25+18+40+20
[self.view addSubview:self.scrollView];
self.scrollView.frame = self.view.bounds;
self.scrollView.contentSize = CGSizeMake(rect_screen.size.width, contentHeight+250);
[self.scrollView addSubview:self.safariBtn];
[self.scrollView addSubview:self.textLabel];
[self.scrollView addSubview:self.shareVC.shareContentView];
[self.scrollView addSubview:self.cancelBtn];
self.safariBtn.frame = CGRectMake(CGRectGetMinX(self.scrollView.frame)+30, CGRectGetMinY(self.scrollView.frame)+20, 40, 60);
self.textLabel.frame = CGRectMake(CGRectGetMinX(self.scrollView.frame)+30, CGRectGetMaxY(self.safariBtn.frame)+20, rect_screen.size.width-60, 18);
self.shareVC.shareContentView.frame = CGRectMake(CGRectGetMinX(self.scrollView.frame), CGRectGetMaxY(self.textLabel.frame), CGRectGetWidth(self.scrollView.frame), contentHeight);
self.cancelBtn.frame = CGRectMake(CGRectGetMinX(self.scrollView.frame)+20, CGRectGetMaxY(self.shareVC.shareContentView.frame), rect_screen.size.width-40, 50);
}
-(UIScrollView *)scrollView{
if (!_scrollView) {
_scrollView = [UIScrollView new];
_scrollView.clipsToBounds = YES;
_scrollView.alwaysBounceVertical = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollEnabled = YES;
_scrollView.backgroundColor = [UIColor clearColor];
}
return _scrollView;
}
- (labelButton*)safariBtn {
if (!_safariBtn) {
_safariBtn = [[labelButton alloc]init];
[_safariBtn initWithTarget:self selector:@selector(openLinkEvent) text:@"用Safari打开"];
}
return _safariBtn;
}
- (UILabel*)textLabel {
if (!_textLabel) {
_textLabel = [[UILabel alloc] init];
_textLabel.text = @"分享到";
_textLabel.font = appFont(TEXT_TWO_LEVELSIZE, YES);
_textLabel.textColor = [UIColor colorWithHexString:TextBlack];
_textLabel.backgroundColor = [UIColor clearColor];
}
return _textLabel;
}
-(shareContent *)shareVC{
if (!_shareVC) {
_shareVC = [shareContent new];
_shareVC.baseController = self;
_shareVC.backgroundColor = [UIColor redColor];
_shareVC.delegate = self;
_shareVC.isSimpleShareView = NO;
}
return _shareVC;
}
- (TPCustomButton*)cancelBtn {
if (!_cancelBtn) {
_cancelBtn = [[TPCustomButton alloc] init];
_cancelBtn.title = @"取消";
[_cancelBtn addTarget:self action:@selector(cancelEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelBtn;
}
-(void)setContentBO:(contentObjectBO *)bo{
_contentBO = bo;
self.shareVC.contentBO = _contentBO;
}
#pragma mark -- delegate
-(void)didDismissShareContent:(UIView *)contentView{
if ([self.delegate respondsToSelector:@selector(cancelShare:)]) {
[self.delegate cancelShare:NO];
}
}
#pragma mark - button event
- (void)openLinkEvent {
if ([self.delegate respondsToSelector:@selector(openLinkWithSafari)]) {
[self.delegate openLinkWithSafari];
}
}
- (void)cancelEvent:(UIButton*)btn {
if ([self.delegate respondsToSelector:@selector(cancelShare:)]) {
[self.delegate cancelShare:YES];
}
}
@end
|