GCTagList类似于iOS邮件应用中的发件人或收件人标签。
简单地复制classes
文件夹和assets
文件夹到您的项目中,并确保您已链接QuartzCore.framework
框架。
labelFont
属性与GCTagList
。/**
* labelBackgroundColor's Priority > gradientColors,
* if labelBackgroundColor and gradientColors all nil,
* will use default color #E0EAF4
*/
@property (nonatomic, GC_STRONG) UIColor *labelBackgroundColor;
/**
* if gradientColors's count is less 2, will use default labelBackgroundColor;
*/
@property (nonatomic, GC_STRONG) NSArray *gradientColors; ///< ...
@property (nonatomic, GC_STRONG) NSArray *gradientLocations; ///< can be nil …
有两个属性已被弃用
@property (nonatomic, GC_STRONG) UIColor *startGradientColor __deprecated;
@property (nonatomic, GC_STRONG) UIColor *endGradientColor __deprecated;
- (void)reloadTagLabelWithRange:(NSRange)range withAnimation:(BOOL)animated;
- (void)deleteTagLabelWithRange:(NSRange)range withAnimation:(BOOL)animated;
- (void)insertTagLabelWithRange:(NSRange)range withAnimation:(BOOL)animated;
我尝试模仿UITableView的方式 - @greenchiu
实现GCTagListDataSource并调用公共方法reloadData
-(void)viewDidLoad {
[super viewDidLoad];
GCTagList* taglist = [[GCTagList alloc] initWithFrame:CGRectMake(0, 180, 320, 200)];
taglist.firstRowLeftMargin = 80.f;
taglist.dataSource = self;
[self.view addSubview:taglist];
[taglist reloadData];
}
- (NSInteger)numberOfTagLabelInTagList:(GCTagList *)tagList {
return self.tagNames.count;
}
- (GCTagLabel*)tagList:(GCTagList *)tagList tagLabelAtIndex:(NSInteger)index {
static NSString* identifier = @"TagLabelIdentifier";
GCTagLabel* tag = [tagList dequeueReusableTagLabelWithIdentifier:identifier];
if(!tag) {
tag = [GCTagLabel tagLabelWithReuseIdentifier:identifier];
tag.labelBackgroundColor = [UIColor colorWithRed:84/255.f green:164/255.f blue:222/255.f alpha:1.f];
}
[tag setLabelText:self.tagNames[index]
accessoryType:GCTagLabelAccessoryCrossFont];
return tag;
}
/**
* after reloadData, if the height of TagList has changed, will call this method.
*/
- (void)tagList:(GCTagList *)taglist didChangedHeight:(CGFloat)newHeight;
/**
* Tapped the TagLabel, will call this mehtod.
*/
- (void)tagList:(GCTagList *)taglist didSelectedLabelAtIndex:(NSInteger)index;
/**
* Tapped the TagLabel's accessoryButton, will call this mehtod.
*/
- (void)tagList:(GCTagList *)tagList accessoryButtonTappedAtIndex:(NSInteger)index;
/**
* if implement protocol <GCTagLabelListDataSource> method 'maxNumberOfRowAtTagList'
* and the taglist's rows is more than the maxRow, this method will be call.
*
* @retVal NSString the text for the TagLabel of theMaxRow's last one.
*/
- (NSString*)tagList:(GCTagList *)tagList labelTextForGroupTagLabel:(NSInteger)interruptIndex;
/**
* how many count for taglist to display.
*/
- (NSInteger)numberOfTagLabelInTagList:(GCTagList*)tagList;
/**
* the taglabel At index in the taglist.
*/
- (GCTagLabel*)tagList:(GCTagList*)tagList tagLabelAtIndex:(NSInteger)index;
@optional
/**
* the max row at taglist.
*/
- (NSInteger)maxNumberOfRowAtTagList:(GCTagList*)tagList;
/**
* accessory type of the group taglabel.
*/
- (GCTagLabelAccessoryType)accessoryTypeForGroupTagLabel;
如果您在您的应用中使用此控件,请告诉我!
版权所有(c)2013 Green Chiu,http://greenchiu.github.com/许可协议MIT (http://www.opensource.org/licenses/mit-license.php)
本协议授予任何获得软件副本和关联文档文件(下称“软件”)的人,免费使用软件的权利,不得限制在包括但不限于以下权利:使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许他人因其所提供软件而操作权,但以以下条件为准
上述版权声明和本许可证应包括在所有副本或软件的实质性部分中。
本软件按“原样”提供,不提供任何形式的质量保证,包括明示或暗示的适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权持有者均不对任何索赔、损害或其他责任承担任何责任,无论基于合同行为、侵权行为或其他任何法律责任,无论是否因软件或软件的使用或任何其他方式而出现。