0
日安同胞的程序員,第三和其它連續UIButtons將不會出現在UIScrollView中
它一直小時了,因爲我已經嘗試解決這個問題。我打算創建一些類似於Facebook iOS應用程序的菜單視圖。問題是,我只能在UIScrollView
中添加最多兩個UIButtons
,第三個和其他連續的按鈕不會顯示出來。我希望你能幫助我。
這裏是代碼塊:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = NO;
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
if(i == 0)
{
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; //Creates a UIButton
button.frame = CGRectMake(25, 65, 70, 70); //sets the coordinates and dimensions of UIButton
button.backgroundColor = [UIColor clearColor]; //sets the background color
[button addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; //sets the target and action for the button
[button setBackgroundImage:[UIImage imageNamed:@"Message Board Icon-57.png"] forState:UIControlStateNormal]; //sets the background Image
[subview addSubview:button];
[button release];
UIButton *button2 = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; //Creates a UIButton
button2.frame = CGRectMake(125, 175, 70, 70); //sets the coordinates and dimensions of UIButton
button2.backgroundColor = [UIColor clearColor]; //sets the background color
[button2 addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; //sets the target and action for the button
[button2 setBackgroundImage:[UIImage imageNamed:@"Profile Page Icon-57.png"] forState:UIControlStateNormal]; //sets the background Image
[subview addSubview:button2];
[button2 release];
UIButton *button3 = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; //Creates a UIButton
button3.frame = CGRectMake(125, 65, 70, 70); //sets the coordinates and dimensions of UIButton
button3.backgroundColor = [UIColor clearColor]; //sets the background color
[button3 addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; //sets the target and action for the button
[button3 setBackgroundImage:[UIImage imageNamed:@"iCalendar Icon-57.png"] forState:UIControlStateNormal]; //sets the background Image
[subview addSubview:button3];
[button3 release];
}
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
}
當您將類型更改爲圓角矩形時,按鈕顯示出來嗎? – dasdom
你必須添加你的UIview *子視圖到scrollView來顯示它和按鈕。只是做,[scrollview addsubview:子視圖]; –
我現在已經能夠發現問題了。在我的圖像名稱中存在一些拼寫錯誤,這導致了它們被添加到UIScrollView中的不一致性......感謝@dasdom和@iphonePlayer花時間閱讀我的關注。 –