内容区域设置在NIB设置中的UIScrollView中不起作用

时间:2014-11-13 12:18:34

标签: objective-c

我已经在NIB文件中设置了UIScrollView的内容区域,但我可以看到它不再可滚动。

2 个答案:

答案 0 :(得分:4)

当您以编程方式添加某些视图时,必须添加代码(以编程方式),在实现(.m)文件的viewDidLoad方法中添加UIButton的好地方,这里是一个示例:

  - (void)viewDidLoad
{
[super viewDidLoad];

// other code...

UIButton *newButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 40, 40)];
[newButton setTitle:@"ProButton" forState:UIControlStateNormal];
// more properties you can configurate. See Apple doc
[newButton addTarget:self action:@selector(methodToFire:) forControlEvents:UIControlEventTouchUpInside];
// more action you can configurate for event...
[self.view addSubview:newButton];

// more code...
}

答案 1 :(得分:2)

尝试使用此代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(buttonClickMethod:)
 forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Button Title" forState:UIControlStateNormal];
button.frame = CGRectMake(50.0, 100.0, 160.0, 40.0);
[view addSubview:button];