//
// 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
网友评论