我創建與在Xcode 3個按鈕的圖,該代碼如下:如何距設置爲這些UIButtons
UIImage *firstButtonImg = [UIImage imageNamed:(@"firstButton")];
UIImage *firstButtonImgHighlighted = [UIImage imageNamed:(@"firstButtonHightlighted")];
self.firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[firstButton setBackgroundImage:firstButtonImg forState:UIControlStateNormal];
[firstButton setBackgroundImage:firstButtonImgHighlighted forState:UIControlStateHighlighted];
self.firstButton.frame = CGRectMake(50, 60+self.aboutViewTop.frame.size.height+20, firstButtonImg.size.width, firstButtonImg.size.height);
[firstButton addTarget:self action:@selector(firstButtonEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:firstButton];
UIImage *secondButtonImg = [UIImage imageNamed:(@"secondButton")];
UIImage *secondButtonImgHighlighted = [UIImage imageNamed:(@"secondButtonHighlighted")];
self.secondButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[secondButton setBackgroundImage:secondButtonImg forState:UIControlStateNormal];
[secondButton setBackgroundImage:secondButtonImgHighlighted forState:UIControlStateHighlighted];
self.secondButton.frame = CGRectMake(50, 60+aboutViewTop.frame.size.height+firstButton.frame.size.height+20.f, secondButtonImg.size.width, secondButtonImg.size.height);
[secondButton addTarget:self action:@selector(secondButtonEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:secondButton];
UIImage *thirdButtonImg = [UIImage imageNamed:(@"thirdButton")];
UIImage *thirdButtonImgHighlighted = [UIImage imageNamed:(@"thirdButtonHighlighted")];
self.thirdButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[thirdButton setBackgroundImage:thirdButtonImg forState:UIControlStateNormal];
[thirdButton setBackgroundImage:thirdButtonImgHighlighted forState:UIControlStateHighlighted];
self.thirdButton.frame = CGRectMake(50, 60+aboutViewTop.frame.size.height+firstButton.frame.size.height+secondButton.frame.size.height+20.f, thirdButtonImg.size.width, thirdButtonImg.size.height);
[thirdButton addTarget:self action:@selector(thirdButtonEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:thirdButton];
但這些按鈕是緊密放置,而不20空間我在它們之間加入,我想不通爲什麼
請幫我
請捫心自問,如果你真的需要做的代碼UI工作,而不是使用界面生成器。使用自動佈局可以節省數小時和數小時的努力來解決這類問題。 – 2015-03-03 13:39:56