UIScrollView 子类,允许添加高度可定制的标签列表。您可以自定义颜色、边框半径和标签尾巴。标签可以批量添加或逐个动态添加。新插入的标签将自动在滚动视图中排列。
pod 'AMTagListView'
当使用桥接头时
#import <AMTagListView.h>
当使用动态框架时
@import AMTagListView
您可以在 Storyboard 中创建 AMTagListView
或通过编程方式
// Init
AMTagListView *tagListView = [[AMTagListView alloc] initWithFrame:frame];
[self.view addSubview:tagListView];
let tagListView = AMTagListView(frame: frame)
view.addSubview(tagListView)
// Add one tag
[self.tagListView addTag:@"my tag"];
// Add multiple tags
[self.tagListView addTags:@[@"my tag", @"some tag"]];
// Add one tag
tagListView.addTag("my tag")
// Add multiple tags
tagListView.addTags(["my tag", "some tag"])
使用上述方法调用重新排列标签。您还可以使用这些方法的 andRearrange:
版本来避免自动重新排列。当添加大量标签时,这非常有用。这样做时,您必须手动强制重新排列操作。
[self.tagListView rearrangeTags];
您还可以通过设置 tagAlignment
属性并调用 rearrangeTags
来将标签对齐到左侧或右侧。
使用 AMTagView 的 UIAppearance 选择器来自定义外观
[[AMTagView appearance] setRadius:10];
AMTagView.appearance().radius = 10
您可以使用 addTag:withUserInfo:
向单个标签添加负载。
[self.tagListView addTag:@"hello" withUserInfo:@{ @"data": somePayload }];
您可以通过scrollDirection
属性来控制滚动方向。
[self.tagListView setScrollDirection:AMScrollDirectionHorizontal];
以下是可以修改的属性。
// Tag's corner radius
[[AMTagView appearance] setRadius:float]
// Tail's length
[[AMTagView appearance] setTagLength:float]
// Inner padding of the tag label
[[AMTagView appearance] setInnerTagPadding:float]
// Radius of the hole punched in the tail
[[AMTagView appearance] setHoleRadius:float]
// Text padding (x for horizontal padding, y for vertical)
[[AMTagView appearance] setTextPadding:CGPoint]
// Text font
[[AMTagView appearance] setTextFont:UIFont]
// The text color
[[AMTagView appearance] setTextColor:UIColor]
// Tag main color
[[AMTagView appearance] setTagColor:UIColor]
// Tag label background color
[[AMTagView appearance] setInnerTagColor:UIColor]
此方法询问代理是否可以添加指定的标签。该方法还会显示结果内容大小。
- (BOOL)tagList:(AMTagListView *)tagListView shouldAddTagWithText:(NSString *)text resultingContentSize:(CGSize)size;
此方法询问代理是否可以添加指定的一批标签。该方法还会显示结果内容大小。
- (BOOL)tagList:(AMTagListView *)tagListView shouldAddTagsWithText:(NSArray *)text resultingContentSize:(CGSize)size;
在删除标签时调用。
- (void)tagList:(AMTagListView *)tagListView didRemoveTag:(UIView<AMTag> *)tag;
要运行测试套件,请安装xcpretty
gem,在Tests
文件夹中执行pod install
,并在根目录中运行 rake 任务。
Andrea Mazzini。我提供自由职业工作,欢迎联系我。
想要支持这些免费库的开发吗?请给我买杯咖啡
感谢 Orta Therox 以及所有慷慨提交pull请求的人。
Copyright (c) 2015 Andrea Mazzini. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.