sách gpt4 ai đã đi

Đóng gói đơn giản menu lựa chọn thả xuống của iOS

In lại Tác giả:qq735679552 Thời gian cập nhật: 2022-09-28 22:32:09 25 4
mua khóa gpt4 Nike

CFSDN nhấn mạnh vào việc tạo ra giá trị thông qua mã nguồn mở. Chúng tôi cam kết xây dựng một nền tảng chia sẻ tài nguyên để mọi người làm CNTT có thể tìm thấy thế giới tuyệt vời của riêng mình tại đây.

Bài đăng trên blog CFSDN iOS drop-down selection menu simple encapsulation này được tác giả thu thập và biên soạn. Nếu bạn quan tâm đến bài viết này, hãy nhớ thích nó.

Ví dụ bài viết này chia sẻ một mã menu thả xuống iOS đơn giản được đóng gói để bạn tham khảo. Nội dung cụ thể như sau.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
hai mươi mốt
hai mươi hai
hai mươi ba
hai mươi bốn
25
26
//
// OrderListDownMenu.h
 
#nhập
 
@protocol OrderListDownMenuDelegate
 
- ( vô hiệu )OrderListDownMenu:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
 
@kết thúc
 
định nghĩa kiểu vô hiệu (^Bỏ qua)( vô hiệu );
 
@interface OrderListDownMenu: UIView
 
@property (không phải nguyên tử, mạnh) UITableView *tableView;
@property (không nguyên tử, gán) id ủy nhiệm;
@property (không phải nguyên tử, mạnh) NSArray *arrData;
@property (không phải nguyên tử, mạnh) NSArray *arrImgName;
@property (nonatomic, copy) Bỏ qua bỏ qua;
 
- (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;
 
- ( vô hiệu )bỏ quaVớiHoàn thành:( vô hiệu (^)(OrderListDownMenu *object))hoàn thành;
 
@kết thúc
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
hai mươi mốt
hai mươi hai
hai mươi ba
hai mươi bốn
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#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;
     }
     
     // Đặt màu nền
     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 {
   
   //[màu sắc[chuỗi] setFill];
   
   //Chuẩn bị bảng vẽ cho chế độ xem hiện tại
   
   CGContextRef ngữ cảnh = UIGraphicsGetCurrentContext();
   
   //Sử dụng path để vẽ một hình tam giác
   
   CGContextBeginPath(bối cảnh); //đánh dấu
   
   CGContextMoveToPoint(bối cảnh,
              phảiXem - 13, 53); //Đặt điểm bắt đầu
   
   CGContextAddLineToPoint(bối cảnh,
               rightToView - 21, TopToView);
   
   CGContextAddLineToPoint(bối cảnh,
               rightToView - 4, TopToView);
   
   CGContextClosePath(bối cảnh); //Dấu kết thúc đường dẫn, nếu không được viết, mặc định là đóng
   
 
   [self.tableView.backgroundColor setFill]; //Đặt màu tô
   
   [self.tableView.backgroundColor setStroke]; //Đặt màu đường viền
   
   CGContextDrawPath(bối cảnh,
            kCGPathFillStroke); //Vẽ đường dẫn
}
 
@kết thúc

Trên đây là toàn bộ nội dung bài viết này, hy vọng sẽ giúp ích cho việc học tập của mọi người, và mong các bạn ủng hộ tôi.

Cuối cùng, bài viết này về việc đóng gói đơn giản menu lựa chọn thả xuống iOS kết thúc tại đây. Nếu bạn muốn biết thêm về việc đóng gói đơn giản menu lựa chọn thả xuống iOS, vui lòng tìm kiếm các bài viết CFSDN hoặc tiếp tục duyệt các bài viết liên quan. Tôi hy vọng bạn sẽ ủng hộ blog của tôi trong tương lai! .

25 4 0
qq735679552
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com