目前,我指的是this post和我能夠創建一個2 * 2的網格視圖編程創建iphone 2 * 2和2 * 1網格視圖
int rows = 2;
int cols = 2;
float gridWidth = 1024.0;
float gridHeight = 1024.0;
float buttonWidth = 100.0;
float buttonHeight = 100.0;
// float gapHorizontal = (gridWidth - (buttonWidth * rows))/(rows + 1);
// float gapVertical = (gridHeight - (buttonHeight * cols))/(cols + 1);
float gapHorizontal = 40;
float gapVertical = 40;
float offsetX;
float offsetY;
int count = 0;
do {
offsetX = gapHorizontal + ((count % rows) * (buttonWidth + gapHorizontal));
offsetY = gapVertical + ((count/rows) * (buttonHeight + gapVertical));
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(offsetX, offsetY, buttonWidth, buttonHeight)];
view.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view];
offsetX+= buttonWidth + gapHorizontal;
count++;
} while(count < rows * cols);
但是當我嘗試創建一個2 * 1網格視圖
通過改變這
int rows = 2;
int cols = 1;
我不能這樣做。它只能創建2個視圖。
有沒有簡單的解決方案可用於此?
通過調試器的步驟並檢查每個變量中的每個值。你應該能夠發現問題所在。 – TigerCoding 2012-03-10 21:56:04
我發現我的解決方案通過以下這個:http://stackoverflow.com/questions/9782499/creating-a-new-row-of-uibutton-programatically/9782670#9782670 – user1227928 2012-03-20 07:28:45