Giter Site home page Giter Site logo

weijentu / automatic-height-tagcells Goto Github PK

View Code? Open in Web Editor NEW
225.0 9.0 36.0 1.36 MB

This is a sample project to implement features with dynamic height of UITableViewCell based on autolayout, tags aligned automatically and clickable tags.

Home Page: http://www.xcodeproj.com

License: MIT License

Objective-C 54.93% Swift 45.07%
autolayout ios swift objective-c xcode uitableview uitableviewcell

automatic-height-tagcells's Introduction

Automatic-height-tagcells

The practice project meets some criteria:

  • Dynamic height of UITableViewCell based on autolayout
  • Tags have to be aligned automatically
  • Tags have to be clickalbe

Usage

Construct your own data source in the class TagGroups

  • ObjC
    /* An initialization sample of AHTag with Objective-C */
    AHTag *tag = [AHTag new];
    tag.category = @"Genre";
    tag.title = @"Classic";
    tag.color = [UIColor colorWithRed:1 green:0.56 blue:0.56 alpha:1];
    tag.url = [NSURL URLWithString:@"http://www.coldyam.com"];
    tag.enabled = @YES;
  • Swift
    /* An initialization sample of AHTag with Swift 3.0 */
    let tag = AHTag(category: "Genre", 
                       title: "Classical", 
                       color: UIColor(red: 0.626, green: 0.56, blue: 1, alpha: 1), 
                         URL: NSURL(string: "http://itunes.com"), 
                     enabled: true)

screenshot

automatic-height-tagcells's People

Contributors

vvit avatar weijentu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

automatic-height-tagcells's Issues

changing the json file with array / nsdictionary as datasource

hi,, can we change the data source from json file, to nsdictionary or array?

me and my friend on a combine project (objc-swift), and him as a swift developer using this library but having a difficulty of getting data to tags label using nsdictionary or array, and he change it to sqllite, but the issue become bigger.. currently i already convert the code in swift to get the selected data to nsarray, but i still struggling for setup the setTags file.

if self.fundArr.count != 0 { print(self.fundArr.count) var arrSourceFound = self.fundArr for element in arrSourceFound { print(element) } // for index in 0...self.fundArr.count - 1 { // let sourcefund:SqlLite_SourceFund = self.fundArr.object(at: index) as! SqlLite_SourceFund //// print("data source fund " + sourcefund) //// for (myKey,myValue) in sourcefund { //// print("\(myKey) \t \(myValue)") //// } // arrSourceFound.append(sourcefund) // } cell.label.setTags(arrSourceFound as! [AHTag])

this is what im struggling for, to settags my array as ahtag, its quite hard for me since i am an objective c developer, and this code need to be done using swift (his partt)
the one in commented is what my partner doing,, he changed it to sqllite, but its become a bigger issue, thats why i want to convert it to nsdictionary / nsarray as a datasource

hope anyone here can help me to solve this issue..
regards,
Eka

accessing datasource using simple array

hi, so sorry for my previous opened issue,

at the moment im using your code and try to bypass your data source from json file and do this

`
private func configureCell(_ object: AnyObject, atIndexPath indexPath: IndexPath) {
if object.isKind(of: AHTagTableViewCell.classForCoder()) == false {
abort()
}
let cell = object as! AHTagTableViewCell

    var dataFundArr = NSMutableArray()
    var dataDictionary = [
        "url":"0.25",
        "color":"0xFF8F8F",
        "enabled":"true",
        "category":"data category",
        "title":"aadsa"
    ]
    
    print("data dict")
    for (myKey,myValue) in dataDictionary {
        print("\(myKey) \t \(myValue)")
    }
    dataFundArr.add(dataDictionary)
    
    let tags = dataFundArr
    
    cell.label.setTags(tags as! [AHTag])
}

`

but the compiler is reject it saying

Could not cast value of type 'Swift._SwiftDeferredNSDictionary<Swift.String, Swift.String>' (0x10102b518) to 'AutomaticHeightTagTableViewCell.AHTag' (0x100938468).
2018-05-09 13:55:03.900266+0700 AutomaticHeightTagTableViewCell[15205:3410518] Could not cast value of type 'Swift._SwiftDeferredNSDictionary<Swift.String, Swift.String>' (0x10102b518) to 'AutomaticHeightTagTableViewCell.AHTag' (0x100938468).

the issue is still the same, i want to use my own set of array to generate data instead of json file

Tags in the single row example (Pinterest) are not centered

Allen, this is very cool. Very nicely implemented. 👍🏻

I have one comment though: in the example you provide (see your screenshot for reference), the Pinterest row is misaligned: the tags are not centered in the cell. However, for multi-line rows, it looks fine.

UItableview scrolling not smooth

Hi,

You done a grade work but i m facing small issue when i increase records with around 25 tags Tableview scrolling not smooth and some jerky.

Thanks

Horizontal scrolling for Tableview Cell

Hello @weijentu

Actually, I want a scrollable horizontal cell so that if there is more tag than the height of cell, then it will display you in the next paging screen. So what will be changes require in this current project?

Thanks in a advance!

P.S: I have successfully converted this Obj C code to Swift already. And it's working fine. Thanks!

Gives wrong index if less tags

If I have 3 or 4 tags and I tap on first tag I'm getting index = 3.

This is my view hierarchy View->ScrollView->StackView->View->AHTagsLabel

Use json for data

Very good looking project, I figuring out how to use Firebase data or json to populate the tableview / tags, can you give me some direction where and maybe how?

Swift code

Is there Swift sample code available for this project?

Thanks in advance! :)

The tag is chopped if it's wider than the width of the display

If you have a long enough string, the tag's right side will be chopped off. Consider filling the tag as much as the display's width and add an API to allow to set the ellipsis (using NSLineBreakMode). Something like:

 /* An initialization sample of AHTag with Objective-C */
AHTag *tag = [AHTag new];
tag.category = @"Genre";
tag.title = @"This is a really, really long string that probably won't fit in the tag";
tag.color = [UIColor colorWithRed:1 green:0.56 blue:0.56 alpha:1];
tag.url = [NSURL URLWithString:@"http://www.coldyam.com"];
tag.enabled = @YES;
tag.lineBreakMode = NSLineBreakByTruncatingMiddle;

That would make the tag look great. Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.