Skip to content

shebinkoshy/DropDown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSDropDown

Its a view with tableView

Carthage compatible Version License Platform Join the chat at https://gitter.im/iOS-objectiveC-swift/SSDropDown

# For latest release in cocoapods
pod 'SSDropDown'

Carthage

git "https://github.com/shebinkoshy/DropDown.git" "carthage"

SwiftPM

To use SwiftPM, you should use Xcode 11 to open your project. Click File -> Swift Packages -> Add Package Dependency, enter SSDropdown repo's URL After select the package, you can choose the dependency type as branch with swiftpackage. Then Xcode will setup all the stuff for you.

for simple use

Objective C:

    SSDropDown *dropDown = [[SSDropDown alloc]init];
    dropDown.tag = 901;
    dropDown.delegate = self;
    dropDown.dropDownPosition = kSSDropDownPositionRight;
    dropDown.needToShowArrow = YES;
    dropDown.cornerRadius = 5.0;
    dropDown.dropDownHeight = 120;
    dropDown.dropDownWidth = 100;
    dropDown.arrayItemsToList = @[@"1",@"2",@"3"];
    [dropDown.tableViewDropDownList setShowsVerticalScrollIndicator:NO];
    [dropDown showDropDownForView:yourView withSelectedObject:@"1"];

   #pragma mark - SSDropDownDelegate

   -(void)dropDown:(nonnull SSDropDown*)dropDownViewObj selectedAnObject:(nullable id)selectedDropDownItem dropDownForTheView:(nonnull UIView*)viewForDropDown;
  {
    NSLog(@"tag = %d selected obj %@",(int)dropDownViewObj.tag,selectedDropDownItem);
  }

Swift:

let dropDown = SSDropDown()
        dropDown.tag = 901
        dropDown.delegate = self
        dropDown.dropDownPosition = kSSDropDownPositionRight
        dropDown.needToShowArrow = true
        dropDown.cornerRadius = 5
        dropDown.dropDownHeight = 120
        dropDown.dropDownWidth = 100
        dropDown.arrayItemsToList = ["1","2","3"]
        dropDown.tableViewDropDownList.showsVerticalScrollIndicator = false
        dropDown.show(for: yourView, withSelectedObject: "1")

// MARK: - SSDropDownDelegate
    
    func dropDown(_ dropDownViewObj: SSDropDown, selectedAnObject selectedDropDownItem: Any?, dropDownForTheView viewForDropDown: UIView) {
        print("tag = \(dropDownViewObj.tag) selected obj \(selectedDropDownItem!)")
    }

With custom cell Include below code

dropDown.needCustomCell = YES;
dropDown.dropDownBackgroundColor = [UIColor blueColor];

-(void)dropDown:(nonnull SSDropDown*)dropDownViewObj registerCustomCellForTheDropDownTableView:(nonnull UITableView*)dropDownTableView
{
    [dropDownTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"dropDownCell"];
}

-(nonnull UITableViewCell *)dropDown:(nonnull SSDropDown*)dropDownViewObj dropDownTableView:(nonnull UITableView *)dropDownTableView cellForRowAtIndexPath:(nonnull NSIndexPath *)dropDownIndexPath andSelectedItem:(nullable id)selectedObject;
{
    UITableViewCell *cell = [dropDownTableView dequeueReusableCellWithIdentifier:@"dropDownCell"];
    NSString *title = [dropDownViewObj.arrayItemsToList objectAtIndex:dropDownIndexPath.row];
    cell.textLabel.text = title;
    if ([selectedObject isEqual:title])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.contentView.backgroundColor = [UIColor greenColor];
    cell.backgroundColor = [UIColor greenColor];
    return cell;
}

Advantages

can able to use with any subclass of UIView like UITextField, UIButton.

also with any UI element inside a UITableViewCell or UICollectionViewCell NOTE: For this you should use

-(void)showDropDownForView:(nonnull UIView*)viewForDropDown insideTheCell:(nonnull id)cell withSelectedObject:(nullable id)selectedObject;