国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

下拉彈出列表選擇項效果

2019-11-14 18:42:06
字體:
來源:轉載
供稿:網友

 

右邊菜單中的按鍵,點擊彈出一個列表可選擇,選擇其中一個,響應相應的事件并把文字顯示在右邊的菜單上;彈出下拉效果使用LMDropdownView插件,可以用POD進行加載pod ‘LMDropdownView’;LMDropdownView是把想要的視圖賦給它;

源代碼地址:https://github.com/JxbSir/YiYuanYunGou

效果如下:

 

1:在主頁面先定義按鍵跟綁定視圖(沒寫全的都是屬性中定義了比如btnRigth,dropdownView等):

btnRigth = [UIButton buttonWithType:UIButtonTypeCustom];    [btnRigth addTarget:self action:@selector(btnRightAction) forControlEvents:UIControlEventTouchUpInside];    if(![OyTool ShardInstance].bIsForReview)    {        [self actionCustomNavBtn:btnRigth nrlImage:@"" htlImage:@"" title:@"全部分類▽"];    }    else    {        [self actionCustomNavBtn:btnRigth nrlImage:@"" htlImage:@"" title:[dicTypeName.allValues objectAtIndex:0]];    }    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnRigth];    AllPRoTypeView* tview = [[AllProTypeView alloc] initWithFrame:self.view.bounds];    tview.delegate = self;    //賦于下拉的里效果視圖    dropdownView = [[LMDropdownView alloc] init];    dropdownView.menuBackgroundColor = [UIColor whiteColor];    dropdownView.menuContentView = tview;

 

2:其中對設置按鍵進行的封裝:

- (void)actionCustomNavBtn:(UIButton *)btn nrlImage:(NSString *)nrlImage                  htlImage:(NSString *)hltImage                     title:(NSString *)title {    [btn setImage:[UIImage imageNamed:nrlImage] forState:UIControlStateNormal];    if (hltImage) {        [btn setImage:[UIImage imageNamed:hltImage] forState:UIControlStateHighlighted];    } else {        [btn setImage:[UIImage imageNamed:nrlImage] forState:UIControlStateNormal];    }    if (title) {        btn.titleLabel.font = [UIFont boldSystemFontOfSize:13];        [btn setTitle:title forState:UIControlStateNormal];        [btn setTitle:title forState:UIControlStateHighlighted];        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];    }    [btn sizeToFit];}

 

3:其中btnRightAction響應事件內容(主要用于顯示跟隱藏下拉效果):

- (void)btnRightAction{    if ([dropdownView isOpen])    {        [dropdownView hide];    }    else    {        //[tbViewType reloadData];        [dropdownView showInView:self.view withFrame:CGRectMake(0, 0, mainWidth, self.view.bounds.size.height)];    }}

 

4:AllProTypeView下拉內容的視圖代碼如下(是一個列表):

.h文件內容#import <UIKit/UIKit.h>@protocol AllProTypeViewDelegate- (void)selectedTypeCode:(int)code;@end@interface AllProTypeView : UIView@property(nonatomic,weak)id<AllProTypeViewDelegate> delegate;@end.m文件內容@interface AllProTypeView ()<UITableViewDataSource,UITableViewDelegate>{    UITableView     *tbView;        NSArray         *arrOfType;    NSArray         *arrOfTypeImage;    NSInteger       indexType;        __weak id<AllProTypeViewDelegate> delegate;}@end@implementation AllProTypeView@synthesize delegate;- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if(self)    {        self.backgroundColor = [UIColor redColor];                tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, mainWidth, frame.size.height) style:UITableViewStyleGrouped];        tbView.delegate = self;        tbView.dataSource = self;        tbView.backgroundColor = [UIColor whiteColor];        tbView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;        tbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;        [self addSubview:tbView];                if(![OyTool ShardInstance].bIsForReview)        {            arrOfType = @[@"全部分類",@"手機數碼",@"電腦辦公",@"家用電器",@"化妝個護",@"鐘表首飾",@"其他商品"];            arrOfTypeImage = @[@"sort0",@"sort100",@"sort106",@"sort104",@"sort2",@"sort222",@"sort312"];        }        else        {            arrOfType = @[@"家用電器",@"化妝個護",@"鐘表首飾",@"其他商品"];            arrOfTypeImage = @[@"sort104",@"sort2",@"sort222",@"sort312"];        }    }    return self;}#pragma mark - tableview- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return  arrOfType.count;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return 44;}- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 0.1;}- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{    return 0.1;}- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    //static NSString *CellIdentifier = @"Cell";    UITableViewCell *cell =  nil;//(UITableViewCell*)[tableView  dequeueReusableCellWithIdentifier:CellIdentifier];    if(cell == nil)    {        cell = [[UITableViewCell alloc] init];    }    cell.textLabel.text = [NSString stringWithFormat:@"        %@", [arrOfType objectAtIndex:indexPath.row]];    NSString* name = [arrOfTypeImage objectAtIndex:indexPath.row];     if(indexPath.row == indexType)    {        name = [NSString stringWithFormat:@"%@_checked",name];        cell.textLabel.textColor = mainColor;                UIImageView* imgOK = [[UIImageView alloc] initWithFrame:CGRectMake(mainWidth - 32, 14, 20, 16)];        imgOK.image = [UIImage imageNamed:@"screening_select"];        [cell addSubview:imgOK];    }    else    {        name = [NSString stringWithFormat:@"%@_normal",name];    }    UIImageView* img = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10, 24, 24)];    img.image = [UIImage imageNamed:name];    [cell addSubview:img];    return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    [tableView deselectRowAtIndexPath:indexPath animated:YES];    indexType = indexPath.row;    [tbView reloadData];        if(delegate)    {        NSString* code = [[arrOfTypeImage objectAtIndex:indexPath.row] stringByReplacingOccurrencesOfString:@"sort" withString:@""];        [delegate selectedTypeCode:[code intValue]];    }}@end

注意:列表有綁定是否是被選擇,它顯示的效果是不一樣的,在觸發行時對標識符進行重新賦值,把通過delegate把它傳回主視圖控件器里;

 

5:主控制器里響應上面delegate的內容為:

- (void)selectedTypeCode:(int)code{    iCodeType = code;    [dropdownView hide];        NSString* key = [NSString stringWithFormat:@"%d",code];    NSString* name = [dicTypeName objectForKey:key];        [self actionCustomNavBtn:btnRigth nrlImage:@"" htlImage:@"0" title:name];       //重新綁定列表顯示內容    __weak typeof (self) wSelf = self;    curPage = 1;    [self getData:^{        __strong typeof (wSelf) sSelf = wSelf;        sSelf->listNew = nil;    }];}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇原县| 邳州市| 芜湖市| 永吉县| 桐乡市| 历史| 钟祥市| 航空| 思南县| 惠来县| 阜新市| 姜堰市| 上栗县| 阜宁县| 吕梁市| 葵青区| 岢岚县| 界首市| 滨海县| 贵州省| 灵武市| 原阳县| 和顺县| 沙雅县| 长丰县| 谢通门县| 老河口市| 昌吉市| 文成县| 锦屏县| 福海县| 五台县| 张北县| 旅游| 龙陵县| 英山县| 鹤岗市| 论坛| 长汀县| 尖扎县| 邵阳市|