固定——宽高
- (void)initShareMenuWithChannels:(NSArray<NSNumber *> *)channels shareTitle:(NSString *)shareTitle
{
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.7];
[self addTarget:self action:@selector(bgAction:) forControlEvents:UIControlEventTouchUpInside];
UIView *menuBgView = [[UIView alloc] init];
menuBgView.backgroundColor = CLineColor;
[self addSubview:menuBgView];
CGFloat currentY = 15;
// 列数
NSInteger column = 3;
//CGFloat viewWidth = (SCREEN_WIDTH - (column+1)*marginX) / column;
CGFloat viewWidth = 60;
CGFloat viewHeight = viewWidth;
//CGFloat marginX = 20;
CGFloat marginX = (SCREEN_WIDTH - viewWidth*column) / (column+1);
CGFloat marginY = 20;
//分享的提示性标题(根据是否有标题文字传入来现实)
if (shareTitle && shareTitle.length > 0) {
///选取分享方式
UILabel *titileLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, currentY, SCREEN_WIDTH, 20)];
titileLabel.text = shareTitle;
titileLabel.font = [UIFont systemFontOfSize:14];
titileLabel.textColor = [UIColor blackColor];
titileLabel.textAlignment = NSTextAlignmentCenter;
[menuBgView addSubview:titileLabel];
currentY += 20;
}
UIView *tempView;
for (int i = 0; i < channels.count; i++) {
UIView *view = [[UIView alloc] init];
[view showBlueLayer];
[menuBgView addSubview:view];
// view所在行
NSInteger row = i / column;
// view所在列
NSInteger col = i % column;
// positionX
CGFloat viewX = marginX + (viewWidth+marginX)*col;
// positionY
CGFloat viewY = marginY + (viewHeight+marginY)*row + currentY;
// view的frame
view.frame = CGRectMake(viewX, viewY, viewWidth, viewHeight);
tempView = view;
}
// 最后一行
//currentY += ((channels.count / column) + 1) * viewHeight;
currentY = CGRectGetMaxY(tempView.frame);
currentY += 20;
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
cancelButton.backgroundColor = [UIColor whiteColor];
cancelButton.frame = CGRectMake(17, currentY, SCREEN_WIDTH - 17*2, 45);
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton setTitleColor:COneLevelColor forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[menuBgView addSubview:cancelButton];
currentY += 45;
currentY += 20;
menuBgView.frame = CGRectMake(0, SCREEN_HEIGHT - currentY, SCREEN_WIDTH, currentY);
}
不固定——宽高
- (void)initShareMenuWithChannels:(NSArray<NSNumber *> *)channels shareTitle:(NSString *)shareTitle
{
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.7];
[self addTarget:self action:@selector(bgAction:) forControlEvents:UIControlEventTouchUpInside];
UIView *menuBgView = [[UIView alloc] init];
menuBgView.backgroundColor = CLineColor;
[self addSubview:menuBgView];
CGFloat currentY = 15;
// 列数
NSInteger column = 3;
CGFloat viewWidth = (SCREEN_WIDTH - (column+1)*marginX) / column;
CGFloat viewHeight = viewWidth;
CGFloat marginX = 20;
CGFloat marginY = 20;
//分享的提示性标题(根据是否有标题文字传入来现实)
if (shareTitle && shareTitle.length > 0) {
///选取分享方式
UILabel *titileLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, currentY, SCREEN_WIDTH, 20)];
titileLabel.text = shareTitle;
titileLabel.font = [UIFont systemFontOfSize:14];
titileLabel.textColor = [UIColor blackColor];
titileLabel.textAlignment = NSTextAlignmentCenter;
[menuBgView addSubview:titileLabel];
currentY += 20;
}
UIView *tempView;
for (int i = 0; i < channels.count; i++) {
UIView *view = [[UIView alloc] init];
[view showBlueLayer];
[menuBgView addSubview:view];
// view所在行
NSInteger row = i / column;
// view所在列
NSInteger col = i % column;
// positionX
CGFloat viewX = marginX + (viewWidth+marginX)*col;
// positionY
CGFloat viewY = marginY + (viewHeight+marginY)*row + currentY;
// view的frame
view.frame = CGRectMake(viewX, viewY, viewWidth, viewHeight);
tempView = view;
}
// 最后一行
//currentY += ((channels.count / column) + 1) * viewHeight;
currentY = CGRectGetMaxY(tempView.frame);
currentY += 20;
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
cancelButton.backgroundColor = [UIColor whiteColor];
cancelButton.frame = CGRectMake(17, currentY, SCREEN_WIDTH - 17*2, 45);
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton setTitleColor:COneLevelColor forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[menuBgView addSubview:cancelButton];
currentY += 45;
currentY += 20;
menuBgView.frame = CGRectMake(0, SCREEN_HEIGHT - currentY, SCREEN_WIDTH, currentY);
}
网友评论