CGRect frame = CGRectMake(10.0, 30.0, 32.0, 29.0);
UIImage *buttonImage = [UIImage imageNamed:@"visit_icon.png"];
UIButton *stopButton = [[UIButton alloc] initWithFrame:frame];
[stopButton setTitle:@"Button" forState:UIControlStateNormal];
[stopButton setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
[stopButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
stopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
stopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[stopButton addTarget:self action:@selector(stopAction:) forControlEvents:UIControlEventTouchUpInside];
我正在添加按钮到我的根视图控制器不起作用 可能我需要将此作为子视图添加到我的视图中 我怎么能这样做?
答案 0 :(得分:0)
你走在正确的轨道上。
在上面代码末尾的UIViewController
子类中执行此操作:
[self.view addSubview: stopButton];