#import "OrderListDownMenu.h"
#define TopToView 63.0f
#define rightToView kScreenWidth - 15.0f
#define LeftToView kScreenWidth - 145.0 - 10.0f
#define CellLineEdgeInsets UIEdgeInsetsMake(0, -80, 0, 0)
#define kScreenWidth [Màn hình chính UIScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
@giao diện OrderListDownMenu()
@property (nonatomic, gán) CGPoint gốc;
@property (không phải nguyên tử, gán) CGFloat rowHeight;
@kết thúc
@implementation OrderListDownMenu
- (kiểu thể hiện)initWithDataArr:(NSArray *)dataArr nguồn gốc:(CGPoint)chiều rộng gốc:(CGFloat)chiều rộng rowHeight:(CGFloat)rowHeight {
self = [siêu initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
nếu như
(bản thân) {
nếu như
(chiều cao hàng <= 0) {
chiều cao hàng = 50;
}
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
self.origin = nguồn gốc;
self.rowHeight = rowHeight;
self.arrData = [bản sao dataArr];
self.tableView = [[phân bổ UITableView] initWithFrame:CGRectMake(origin.x + LeftToView, origin.y + TopToView, width, rowHeight * dataArr.count) style:UITableViewStylePlain];
_tableView.dataSource = bản thân;
_tableView.delegate = bản thân;
[tự thêmSubview:_tableView];
_tableView.backgroundColor = [UIColor màu trắng];
_tableView.layer.cornerRadius = 2;
_tableView.bounces = KHÔNG;
_tableView.layer.cornerRadius = 8;
_tableView.separatorColor = [màu UIColorVớiMàuTrắng:0.3 alpha:1];
_tableView.separatorStyle = UITableViewCellSelectionStyleNone;
[_tableView registerClass:[UITableViewCell
lớp học
]forCellReuseIdentifier:@
"tế bào"
];
nếu như
([self.tableView phản hồi tới Selector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:CellLineEdgeInsets];
}
nếu như
([self.tableView phản hồi tới Selector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:CellLineEdgeInsets];
}
}
trở lại
bản thân;
}
- (
vô hiệu
)bố cụcSubviews {
[siêu layoutSubviews];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
trở lại
self.arrData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
trở lại
self.rowHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@
"tế bào"
];
cell.textLabel.textColor = MÀU_CHỦ_ĐỀ_XÁM_1;
cell.textLabel.font = [Hệ thống UIFontFontOfSize:15];
cell.textLabel.text = self.arrData[indexPath.row];
nếu như
(self.arrImgName.count > indexPath.row) {
cell.imageView.image = [UIImage imageNamed:self.arrImgName[indexPath.row]];
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
UILabel *label = [[UILabel phân bổ] khởi tạo];
nhãn.frame = CGRectMake(0, 49, _tableView.frame.size.width, 0,5);
nhãn.backgroundColor = MÀU_PHÂN_CHỦ_ĐỀ;
[cell.contentView thêmSubview:nhãn];
trở lại
tế bào;
}
- (
vô hiệu
)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
nếu như
([self.delegate phản hồi tới Selector:@selector(OrderListDownMenu:didSelectRowAtIndexPath:)]) {
[self.delegate OrderListDownMenu:tableView didSelectRowAtIndexPath:indexPath];
}
[tableView deselectRowAtIndexPath:indexPath hoạt hình:CÓ];
[tự hủy bỏVớiHoàn thành:nil];
}
- (
vô hiệu
)bỏ quaVớiHoàn thành:(
vô hiệu
(^)(OrderListDownMenu *object))hoàn thành {
__weak__typeof(bản thân) weakSelf = bản thân;
[UIView animateWithDuration:0.2 hoạt ảnh:^{
weakSelf.alpha = 0;
weakSelf.tableView.frame = CGRectMake(weakSelf.origin.x + LeftToView + 145, weakSelf.origin.y + TopToView, 0, 0);
} hoàn thành:^(
BOOL
hoàn thành)
[weakSelf removeFromSuperview];
nếu như
(hoàn thành) {
hoàn thành(weakSelf);
}
nếu như
(yếu bản thân. bỏ qua) {
weakSelf.bỏ qua();
}
}];
}
- (
vô hiệu
)touchesBegan:(NSSet *)touches vớiSự kiện:(UIEvent *)sự kiện {
UITouch *touch = [chạm vào bất kỳ đối tượng nào];
nếu như
(![touch.view isEqual:self.tableView]) {
[tự hủy bỏVớiHoàn thành:nil];
}
}
- (
vô hiệu
)vẽRect:(CGRect)hình chữ nhật {
CGContextRef ngữ cảnh = UIGraphicsGetCurrentContext();
CGContextBeginPath(bối cảnh);
CGContextMoveToPoint(bối cảnh,
phảiXem - 13, 53);
CGContextAddLineToPoint(bối cảnh,
rightToView - 21, TopToView);
CGContextAddLineToPoint(bối cảnh,
rightToView - 4, TopToView);
CGContextClosePath(bối cảnh);
[self.tableView.backgroundColor setFill];
[self.tableView.backgroundColor setStroke];
CGContextDrawPath(bối cảnh,
kCGPathFillStroke);
}
@kết thúc
Tôi là một lập trình viên xuất sắc, rất giỏi!