Coder Social home page Coder Social logo

ahcategoryview's Introduction

AHCategoryView

AHCategoryView acts like a flexible UITabBarController, but upside down, for categorizing different pages of controllers in your app.

The following demo gif is a Pinterest style category navigation bar.

The following demo gif shows that the AHCategoryView's navBar is embedded into a native UINavigatonBar. |

usage

There are only 5 steps to use it:

  1. Adding AHCategoryItem(s) into an array. Each AHCategoryItem describes how a category tab looks like.
  2. Adding VCs into an array.
  3. Configuring AHCategoryView's naBar barStyle.
  4. Create a AHCategoryView instance with the item array and VC array then add it into a view.
  5. Optionally, when there's a related remote notification coming into your app for a specific category, you can use categoryView.setBadge to set badge number. See the second example code in the followings.

You will be spending most of the time creating those AHCategoryItem(s) and configuring a AHCategoryNavBarStyle. AHCategoryNavBarStyle is pretty self-explanatory. Read the comments in the source file if you get confused, or just try it out.

Example Code: Pinterest Style

///######## 1. Adding items
        var featureItem = AHCategoryItem()
        featureItem.title = "Feature"
        var chartItem = AHCategoryItem()
        chartItem.title = "Categories"
        var radioItem = AHCategoryItem()
        radioItem.title = "Radio"
        var liveItem = AHCategoryItem()
        liveItem.title = "Live"
        var searchItem = AHCategoryItem()
        searchItem.normalImage = UIImage(named: "search-magnifier")
        searchItem.selectedImage = UIImage(named: "search-magnifier")
        
        let items = [featureItem, chartItem, radioItem, liveItem, featureItem, chartItem, radioItem, liveItem, searchItem]
        
///######## 2. Adding VCs
        ///NOTE: You can have more items than VCs. In this case the searchItem is extra, so you won't be able to scroll VCs to the searchItem and you can only tap to it.
        for _ in 0..<8 {
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.random()
            childVCs.append(vc)
        }
        
///######## 3. Configuring barStyle
        var style = AHCategoryNavBarStyle()
//        style.contentInset.left = 100.0
//        style.contentInset.right = 100.0
        style.height = 44.0
        style.fontSize = 20.0
        style.selectedFontSize = 22.0
        style.interItemSpace = 5.0
        style.itemPadding = 8.0
        style.isScrollable = true
        style.layoutAlignment = .left
        /// The view here is referred to categoryView. So if isEmbeddedToView is true, it means the navBar(categoryView's) is attached with categoryView as a whole, instead of being used separately which is the case in the following example code.
        style.isEmbeddedToView = true
        style.showBottomSeparator = true
        style.showIndicator = false
        /// NOTE: The following two colors have to be created in RBG form in order to do a color transition when scrolling VCs.
        style.normalColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1.0)
        style.selectedColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0).withAlphaComponent(0.7)
        style.showBgMaskView = true
        style.bgMaskViewColor = UIColor.lightGray
        
//######### 4. Adding categoryView to view
        let frame = CGRect(x: 0, y: 64.0, width: ScreenSize.width, height: ScreenSize.height - 64.0)
        let categoryView = AHCategoryView(frame: frame, categories: items, childVCs: childVCs, parentVC: self, barStyle: style)
        categoryView.interControllerSpacing = 0.0
        self.view.addSubview(categoryView)
        self.categoryView = categoryView

Example Code: Embed AHCategoryView's navBar into a navigationItem.titleView

///######## 1. Adding items
        var meItem = AHCategoryItem()
        meItem.normalImage = UIImage(named: "me-normal")
        meItem.selectedImage = UIImage(named: "me-selected")
        
        
        var featureItem = AHCategoryItem()
        featureItem.title = "Feature"
        var chartItem = AHCategoryItem()
        chartItem.title = "Charts"
        var categoryItem = AHCategoryItem()
        categoryItem.title = "Categories"
        var radioItem = AHCategoryItem()
        radioItem.title = "Radio"
        var liveItem = AHCategoryItem()
        liveItem.title = "Live"
        
        
        let items = [meItem, featureItem, chartItem, categoryItem, radioItem, liveItem]
        
        ///######## 2. Adding VCs
        for _ in 0..<5 {
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.random()
            childVCs.append(vc)
        }
        
        
        ///######## 3. Configuring barStyle
        
        var style = AHCategoryNavBarStyle()
//        style.contentInset = .zero
        style.interItemSpace = 8.0
        style.itemPadding = 8.0
        style.isScrollable = false
        style.layoutAlignment = .left
        
        ///NOTE: If you want to embed categoryView.navBar into a navigationItem.titleView or some other view, you have to set style.isEmbeddedToView = false.
        /// The view here is referred to categoryView.
        style.isEmbeddedToView = false
        style.showBottomSeparator = false
        style.indicatorColor = UIColor(red: 244.0/255.0, green: 173.0/255.0, blue: 98.0/255.0, alpha: 1.0)
        style.normalColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0)
        style.selectedColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1.0)
        
        //######### 4. Attaching categoryView to navigationItem.titleView
        let frame = CGRect(x: 0, y: 64.0, width: ScreenSize.width, height: ScreenSize.height - 64.0)
        let categoryView = AHCategoryView(frame: frame, categories: items, childVCs: childVCs, parentVC: self, barStyle: style)
        self.view.addSubview(categoryView)
        self.categoryView = categoryView
        categoryView.navBar.frame = CGRect(x: 0, y: 0, width: 359.0, height: 44.0)
        categoryView.navBar.backgroundColor = UIColor.clear
        categoryView.select(at: 1)
        categoryView.setBadge(atIndex: 0, badgeNumber: 10)
        categoryView.setBadge(atIndex: 2, badgeNumber: 3)
        /// Embed navBar to navigationItem.titleView
        self.navigationItem.titleView = categoryView.navBar
        self.navigationController?.navigationBar.barTintColor = UIColor.white

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 8.0+

Installation

AHCategoryView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AHCategoryView"

Author

Anyd Tong, [email protected]

License

AHCategoryView is available under the MIT license. See the LICENSE file for more info.

ahcategoryview's People

Contributors

ivsall2012 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ahcategoryview's Issues

Great pod but why use frame?

Great pod, I like the idea of having this in the navBar. in future updates can you possibly use constraints instead of frame.

Equal Width of Tabs

How to set the equal width of tabs. I have to show 2 tabs on the whole screen.

How to achieve this?

screen shot 2018-10-22 at 11 42 01 am

Veracode Scan issue

Hi,

I have used AHCategoryView in my application everything works fine with library and i have provided it to the Veracode scan for security measurement of app and it gives some of the issue related to memory deallocation and error handling.

I have provide detail information from the scan report below. Can you please look into this and provide necessary fixes in next release.

Associated Flaws by CWE ID:

Use After Free (CWE ID 416)(1 flaw)

Description
This variable reference occurs after its memory allocation has been freed. Using previously freed memory can corrupt valid data such as memory chunk structures or function pointers and may result in the execution of arbitrary code.Ensure that all pointers are set to NULL once the memory they point to has been freed.

Recommendations
Ensure that all pointers are set to NULL once the memory they point to has been freed.

Screenshot 2020-08-14 at 4 40 06 PM

Error Handling(6 flaws)

Description
Error handling problems occur when an application does not properly handle errors that occur during processing. If a function does not generate the correct return/status codes, or if the product does not handle all possible return/status codes that could be generated by a function, then security issues may result. Similarly, failing to catch an exception thrown by a function can potentially cause the program to crash or to behave in an unexpected manner.
This type of problem is most often found in edge conditions that are rarely encountered during normal application use. Presumably, most bugs related to common conditions are found and eliminated during development and testing. In some cases, the attacker can directly control or influence the environment to trigger these edge conditions.

Recommendations
Never ignore return codes, assuming that a function will always succeed. Check for and handle all possible return codes to ensure that all scenarios are covered, including boundary or edge conditions. Subject the application to extensive testing to discover some of the possible instances of where and how errors or return values are not handled.
Use a standard exception handling mechanism to be sure that the application properly handles all types of processing errors. Do not allow the application to throw errors up to the application container, generally the web application server.

Associated Flaws by CWE ID:
Unchecked Return Value (CWE ID 252)(6 flaws)

Description
Ignoring a method's return value can cause the program to overlook unexpected states and conditions. Effort to Fix: 1 - Trivial implementation error.

Screenshot 2020-08-14 at 4 47 01 PM

category view height

In tabbar controller, category view height not managed? My tableview going under the bottom tabbar.

Equal width of Tabs

How to set the equal width of tabs. I have to show 2 tabs on the whole screen.

How to achieve this? Below the image attached.
screen shot 2018-10-22 at 11 42 01 am

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.