1
要顯示20個按鈕中的8個。但我無法翻閱其餘的內容?是否應該顯示滾動條?NSScrollView滾動不起作用?
NSScrollView *nssvFonts = [[NSScrollView alloc] initWithFrame:CGRectMake(200, 200, 200, 400)];
[self.view addSubview:nssvFonts];
[nssvFonts.documentView setFrame: NSMakeRect(0,0,200, 400) ];
nssvFonts.hasVerticalScroller = YES;
for(int i = 0; i < 20; i++){
NSButton *btnDown = [[NSButton alloc] initWithFrame:CGRectMake(0, 50 * i, 200, 50)];
[nssvFonts addSubview:btnDown];
[btnDown setButtonType:NSMomentaryPushInButton];
[btnDown setTitle:[NSString stringWithFormat:@"Down: %d", i]];
}
所以我申請Willeke的意見和做出的增減變化:
NSScrollView *nssvFonts = [[NSScrollView alloc] initWithFrame:CGRectMake(200, 200, 300, 400)];
[self.view addSubview:nssvFonts];
[nssvFonts.documentView setFrame: NSMakeRect(0,0,200, 1000)];
//[nssvFonts.contentView setFrame:NSMakeRect(0, 0, 200, 400)];
nssvFonts.hasVerticalScroller = YES;
for(int i = 0; i < 20; i++){
NSButton *btnDown = [[NSButton alloc] initWithFrame:CGRectMake(50, 50 * i, 200, 50)];
[nssvFonts addSubview:btnDown];
[btnDown setButtonType:NSMomentaryPushInButton];
[btnDown setTitle:[NSString stringWithFormat:@"Down: %d", i]];
}
,但仍然沒有垂直滾動條的顯示,我不能用鼠標,通過它要麼滾動... 1個按鈕或2個按鈕幫助。
應用這個......但我可能失去了一些東西......我說上面的代碼... THX – jdl
'nssvFonts.documentView'爲零,並且您將按鈕添加到滾動視圖而不是文檔視圖。我編輯了我的答案。 – Willeke
thx ...我有另一種看法與此混亂 – jdl