iOS 下拉菜单

//

//  MyDropdownMenu.h

//  M

//

//  Created by zsl on 2017/12/14.

//  Copyright © 2017年zsl. All rights reserved.

//

#import


@interface MyDropdownMenu : UIView


@property(nonatomic,strong)UIButton * scanBtn;

@property(nonatomic,strong)UIButton * addDevice;

@property(nonatomic,strong)UIButton * addFamily;

-(void)createDropDownMenu:(NSInteger)itemNum ItemIconArray:(NSArray *)itemIconArray ItemNameArray:(NSArray *)itemNameArray;

@end

//

//  MyDropdownMenu.m

//  M

//

//  Created by zsl on 2017/12/14.

//  Copyright © 2017年zsl. All rights reserved.

//

#import "MyDropdownMenu.h"

@interface MyDropdownMenu()

@end

@implementation MyDropdownMenu

- (instancetype)initWithFrame:(CGRect)frame

{

 self = [super initWithFrame:frame];

 if (self) {

 self.frame = frame;

        self.layer.cornerRadius = 5;

 self.backgroundColor = [UIColor whiteColor];

    }

    return self;

}

-(void)createDropDownMenu:(NSInteger)itemNum ItemIconArray:(NSArray *)itemIconArray ItemNameArray:(NSArray *)itemNameArray {


 for (NSInteger i = 0; i < itemNum; i++) {


 UIImageView * iconImage = [[UIImageViewalloc]initWithFrame:CGRectMake(Mylength(14),Myheight(15) + i * self.frame.size.height / itemNum,Mylength(20),Mylength(20))];

iconImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",itemIconArray[i]]];

[self addSubview:iconImage];

 UILabel * itemName = [UILabel initWithFrame:CGRectMake(iconImage.frame.size.width + iconImage.frame.origin.x + Mylength(10), Myheight(15) + i * self.frame.size.height / itemNum,self.frame.size.width -iconImage.frame.size.width - iconImage.frame.origin.x , iconImage.frame.size.height) Text:[NSString stringWithFormat:@"%@",itemNameArray[i]] TextAlignment:0 Font:[UIFont systemFontOfSize:Mylength(14)] BackgroundColor:nilTextColor:RGBACOLOR(102, 102, 102, 1)];

[self addSubview:itemName];


    }

    self.scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    [self.scanBtn setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 3)];

    [self addSubview:self.scanBtn];


    self.addFamily = [UIButton buttonWithType:UIButtonTypeCustom];

    [self.addFamily setFrame:CGRectMake(0, self.scanBtn.frame.size.height, self.frame.size.width,self.frame.size.height / 3)];

    [self addSubview:self.addFamily];


    self.addDevice = [UIButton buttonWithType:UIButtonTypeCustom];

    [self.addDevice setFrame:CGRectMake(0, self.frame.size.height - self.scanBtn.frame.size.height -self.addDevice.frame.size.height, self.frame.size.width, self.frame.size.height / 3)];

    [self addSubview:self.addDevice];


}


@end

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 折线图能用到的地方并不是太多,这儿测试了一个简单的双折线图,要用到的可以看看。 动态效果图 再看看iphone5和...
    44767758099b阅读 998评论 0 0
  • AppDelegate.m #import "AppDelegate.h" #import "ViewContro...
    哈喽Mm阅读 351评论 0 0
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,458评论 9 5
  • 01 今年跨年有幸去参加了罗胖的跨年演讲,因为现场信息量太大,第二天想再看看重播,却无意间看到罗胖第二部分...
    李燕_sofia阅读 585评论 5 2
  • 更多 Java 虚拟机方面的文章,请参见文集《Java 虚拟机》 为什么需要使用堆外内存 将长期存活的对象(如 L...
    专职跑龙套阅读 6,906评论 0 3