創(chuàng)建一個(gè)九宮格視圖顯示分享類型
- (void)shareView
{
// 存放按鈕九宮格的容器 view
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectZero];
buttonView.backgroundColor = [UIColor whiteColor];
buttonView.frame = CGRectMake(0.0, 0.0, Main_Screen_Width, 120.0);
[self addSubview:buttonView];
int count = 3; // 每行按鈕的數(shù)量為 3
CGFloat btnWidth = Main_Screen_Width / count; //寬
CGFloat btnHeight = 60.0; //高
for (int i = 0; i < self.dataArray.count; i++) {
int row = i / count; // 行
int col = i % count; // 列
// 分享類型按鈕
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
[shareButton setImage:[UIImage imageNamed:self.dataArray[i]] forState:UIControlStateNormal];
shareButton.frame = CGRectMake(col * btnWidth, row * btnHeight, btnWidth, btnHeight);
shareButton.tag = i;
[shareButton setBackgroundColor:[UIColor whiteColor]];
[shareButton setTitle:@"" forState:UIControlStateNormal];
[shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview:shareButton];
}
}