Content area setting not working in UIScrollView in NIB settings
本问题已经有最佳答案,请猛点这里访问。
我已经在NIB文件中为
以编程方式添加某些视图时,必须添加代码(以编程方式),在实现(.m)文件的viewdidLoad方法中有一个添加uibutton的好地方,这里是一个示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | - (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 3 4 5 6 7 | 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]; |