iOS簡單易用的標籤列表介面

來源:互聯網
上載者:User

標籤:

iOS簡單易用的標籤列表介面 Demo效果:

 Demo示範:
  • 1.使用cocoapods引入YZTagListView,或者直接拖入YZTagListView檔案夾到項目中

  • 2.匯入YZTagListView.h標頭檔

    1 #import "YZTagList.h"
  • 3.建立YZTagListView控制項

    123   YZTagList *tagList = [[YZTagList alloc] init];  tagList.backgroundColor = [UIColor brownColor];  _tagList = tagList;
  • 4.設定YZTagListView屬性(可選)

    12345   // 高度可以設定為0,會自動跟隨標題計算  tagList.frame = CGRectMake(0, 64, self.view.bounds.size.width, 0);  // 設定標籤背景色  tagList.tagBackgroundColor = [UIColor colorWithRed:20 / 255.0 green:160 / 255.0 blue:250 / 255.0 alpha:1];  // 設定標籤顏色  tagList.tagColor = [UIColor whiteColor];  // 設定標籤刪除圖片  tagList.tagDeleteimage = [UIImage imageNamed:@"chose_tag_close_icon"];
  • 5.添加標籤

12345 /** *  添加標籤 * *  @param tagStr 標籤文字 */- (void)addTag:(NSString *)tagStr;
  • 6.添加多個標籤

12345 /** *  添加多個標籤 * *  @param tagStrs 標籤數組,數組存放(NSString *) */- (void)addTags:(NSArray *)tagStrs;
  • 7.刪除標籤

12345 /** *  刪除標籤 * *  @param tagStr 標籤文字 */- (void)deleteTag:(NSString *)tagStr;
  • 8.監聽標籤點擊

123456789 /** *  點擊標籤,執行Block */@property (nonatomic, strong) void(^clickTagBlock)(NSString *tag); 列如:點擊標籤,刪除標籤  // 點擊標籤,就會調用    __weak typeof(_tagList) weakTagList = _tagList;    _tagList.clickTagBlock = ^(NSString *tag){        [weakTagList deleteTag:tag];    };
  • 9.排序功能

12345 屬性:/** *  是否需要排序功能 */@property (nonatomic, assign) BOOL isSort;/** *  在排序的時候,放大標籤的比例,必須大於1 */@property (nonatomic, assign) CGFloat scaleTagInSort;
123456789101112131415161718 執行個體:- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.     NSArray *tags = @[@"小碼哥",@"小碼哥1",@"小碼哥2",@"小碼哥3",@"iOS學院",@"iOS學院1",@"iOS學院2",@"iOS學院3",@"吖了個崢",@"吖了個崢1",@"吖了個崢2",@"吖了個崢3"];    // 建立標籤列表    YZTagList *tagList = [[YZTagList alloc] init];    // 高度可以設定為0,會自動跟隨標題計算    tagList.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64);    // 設定排序時,縮放比例    tagList.scaleTagInSort = 1.3;    // 需要排序    tagList.isSort = YES;    // 標籤尺寸    tagList.tagSize = CGSizeMake(80, 30);    // 不需要自適應標籤列表高度    tagList.isFitTagListH = NO;    [self.view addSubview:tagList];    // 設定標籤背景色    tagList.tagBackgroundColor = [UIColor colorWithRed:20 / 255.0 green:160 / 255.0 blue:250 / 255.0 alpha:1];    // 設定標籤顏色    tagList.tagColor = [UIColor whiteColor];    /**     *  這裡一定先設定標籤列表屬性,然後最後去添加標籤     */    [tagList addTags:tags];}

 

iOS簡單易用的標籤列表介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.