forked from shiweifu/SFTagView
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# OS | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TagsTableCell.h | ||
// WrapViewWithAutolayout | ||
// | ||
// Created by Shaokang Zhao on 15/1/12. | ||
// Copyright (c) 2015年 shiweifu. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class SKTagView; | ||
@interface TagsTableCell : UITableViewCell | ||
@property (weak, nonatomic) IBOutlet SKTagView *tagView; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// TagsTableCell.m | ||
// WrapViewWithAutolayout | ||
// | ||
// Created by Shaokang Zhao on 15/1/12. | ||
// Copyright (c) 2015年 shiweifu. All rights reserved. | ||
// | ||
|
||
#import "TagsTableCell.h" | ||
|
||
@implementation TagsTableCell | ||
|
||
- (void)awakeFromNib { | ||
// Initialization code | ||
} | ||
|
||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { | ||
[super setSelected:selected animated:animated]; | ||
|
||
// Configure the view for the selected state | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// TagsTableViewController.h | ||
// WrapViewWithAutolayout | ||
// | ||
// Created by Shaokang Zhao on 15/1/12. | ||
// Copyright (c) 2015年 shiweifu. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface TagsTableViewController : UITableViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// TagsTableViewController.m | ||
// WrapViewWithAutolayout | ||
// | ||
// Created by Shaokang Zhao on 15/1/12. | ||
// Copyright (c) 2015年 shiweifu. All rights reserved. | ||
// | ||
|
||
#import "TagsTableViewController.h" | ||
#import "TagsTableCell.h" | ||
#import "SKTag.h" | ||
#import "SKTagView.h" | ||
#import <HexColors/HexColor.h> | ||
|
||
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) | ||
|
||
//Cell | ||
static NSString *const kTagsTableCellReuseIdentifier = @"TagsTableCell"; | ||
|
||
@interface TagsTableViewController () | ||
@property (nonatomic, strong) NSArray *colorPool; | ||
@end | ||
|
||
@implementation TagsTableViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.colorPool = @[@"#7ecef4", @"#84ccc9", @"#88abda",@"#7dc1dd",@"#b6b8de"]; | ||
|
||
self.tableView.tableFooterView = [UIView new]; | ||
} | ||
|
||
#pragma mark - Table view data source | ||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
return 1; | ||
} | ||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
return 1; | ||
} | ||
|
||
- (void)configureCell:(TagsTableCell *)cell atIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
cell.tagView.preferredMaxLayoutWidth = SCREEN_WIDTH; | ||
cell.tagView.padding = UIEdgeInsetsMake(12, 12, 12, 12); | ||
cell.tagView.insets = 15; | ||
cell.tagView.lineSpace = 10; | ||
|
||
[cell.tagView.subviews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) { | ||
[obj removeFromSuperview]; | ||
}]; | ||
|
||
//添加Tags | ||
[@[@"Python", @"Javascript", @"HTML", @"Go", @"Objective-C",@"C", @"PHP"] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) | ||
{ | ||
SKTag *tag = [SKTag tagWithText:obj]; | ||
tag.textColor = [UIColor whiteColor]; | ||
tag.fontSize = 15; | ||
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5); | ||
tag.bgColor = [UIColor colorWithHexString:self.colorPool[idx % self.colorPool.count]]; | ||
tag.target = self; | ||
tag.action = @selector(handleBtn:); | ||
tag.cornerRadius = 5; | ||
|
||
[cell.tagView addTag:tag]; | ||
}]; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||
TagsTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kTagsTableCellReuseIdentifier forIndexPath:indexPath]; | ||
[self configureCell:cell atIndexPath:indexPath]; | ||
|
||
return cell; | ||
} | ||
|
||
#pragma mark - Table view delegate | ||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
TagsTableCell *cell = nil; | ||
if (!cell) { | ||
cell = [tableView dequeueReusableCellWithIdentifier:kTagsTableCellReuseIdentifier]; | ||
} | ||
|
||
[self configureCell:cell atIndexPath:indexPath]; | ||
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1; | ||
} | ||
|
||
#pragma mark - User interactions | ||
- (void)handleBtn:(id)sender | ||
{ | ||
NSLog(@"Tapped me"); | ||
} | ||
|
||
@end |