如何在我的 UITableview 底部设置(制作)一个 UIButton?
how to set (make) a UIButton at bottom of my UITableview?
我有两个 Viewcontroller。一个带有 tableview,check button, add button at bottom 。我只是调整了我的 table 视图并将我的添加按钮保留在底部。当用户按下我的添加按钮时,它将转到下一个 viewcontroller(我通过故事板 做了这些事情)
需要:
我需要我的添加按钮应该在我的 table view.when 用户向下滚动我的 table 视图的底部到上方它也应该停留在我的 tableview.i 的中心尝试创建单独的视图,但没有用不能 that.Here 这是我的 viewcontroller.m 文件:
提前致谢!
我用了故事板,所以我做了 iboutlet 并合成了它,
@interface ViewController ()
@property (strong) NSMutableArray *notes;
@end
@implementation ViewController
@synthesize tableView;
@synthesize addButton;
我的viewdidload:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"My Notes";
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
当我按下添加按钮时,它将移动到另一个 viewcontroller:
- (IBAction)addButtonPressed:(id)sender {
AddNoteViewController *addNoteVC = [AddNoteViewController new];
// to remove unused warning....
#pragma unused (addNoteVC)
}
像这样我需要但在中心....
因为您只希望 UIButton
悬停 在您的 UITableView
上,解决方案应该很简单。
我刚刚创建了一个 UIButton
,您可以使用它。
在您初始化 UIButton 的方法中(例如 viewDidLoad
)
yourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[yourBtn setImage:[UIImage imageNamed:@"yourIMG"] forState:UIControlStateNormal];
[yourBtn setTitle:@"+" forState:UIControlStateNormal];
yourBtn.frame = CGRectMake(0, self.view.bounds.size.height -150, buttonwidth, buttonheight);
yourBtn.center = CGPointMake(self.view.center.x, self.view.bounds.size.height -155);
[yourBtn addTarget:self action:@selector(addButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:yourBtn];
如果这不是您的解决方案,请随时评论此答案!
编辑
要设置宽度和按钮高度,只需添加以下内容。写在 yourBtn.frame
行上方!
CGFloat buttonwidth = 57.5;
CGFloat buttonheight = 57.5;
编辑 2.0
您需要先在IB中设置segues标识符。检查:iOS and xcode: how to give a segue a "storyboard id" so that I can programmatically manipulate it
-(IBAction)addButtonPressed:(id)sender {
[self performSegueWithIdentifier:yourSegue sender:self];
}
干杯
我认为您应该在 IB 中编辑或添加 UIButton
的 NSLayoutAttributeCenterX
,而不是 @MasterRazer 的答案中的框架设置。将您的按钮的约束设置为 0 将使您的按钮保持在中间,并且是解决您的问题的一个干净而好的解决方案。
需要:
我需要我的添加按钮应该在我的 table view.when 用户向下滚动我的 table 视图的底部到上方它也应该停留在我的 tableview.i 的中心尝试创建单独的视图,但没有用不能 that.Here 这是我的 viewcontroller.m 文件:
提前致谢!
我用了故事板,所以我做了 iboutlet 并合成了它,
@interface ViewController ()
@property (strong) NSMutableArray *notes;
@end
@implementation ViewController
@synthesize tableView;
@synthesize addButton;
我的viewdidload:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"My Notes";
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
当我按下添加按钮时,它将移动到另一个 viewcontroller:
- (IBAction)addButtonPressed:(id)sender {
AddNoteViewController *addNoteVC = [AddNoteViewController new];
// to remove unused warning....
#pragma unused (addNoteVC)
}
像这样我需要但在中心....
因为您只希望 UIButton
悬停 在您的 UITableView
上,解决方案应该很简单。
我刚刚创建了一个 UIButton
,您可以使用它。
在您初始化 UIButton 的方法中(例如 viewDidLoad
)
yourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[yourBtn setImage:[UIImage imageNamed:@"yourIMG"] forState:UIControlStateNormal];
[yourBtn setTitle:@"+" forState:UIControlStateNormal];
yourBtn.frame = CGRectMake(0, self.view.bounds.size.height -150, buttonwidth, buttonheight);
yourBtn.center = CGPointMake(self.view.center.x, self.view.bounds.size.height -155);
[yourBtn addTarget:self action:@selector(addButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:yourBtn];
如果这不是您的解决方案,请随时评论此答案!
编辑
要设置宽度和按钮高度,只需添加以下内容。写在 yourBtn.frame
行上方!
CGFloat buttonwidth = 57.5;
CGFloat buttonheight = 57.5;
编辑 2.0
您需要先在IB中设置segues标识符。检查:iOS and xcode: how to give a segue a "storyboard id" so that I can programmatically manipulate it
-(IBAction)addButtonPressed:(id)sender {
[self performSegueWithIdentifier:yourSegue sender:self];
}
干杯
我认为您应该在 IB 中编辑或添加 UIButton
的 NSLayoutAttributeCenterX
,而不是 @MasterRazer 的答案中的框架设置。将您的按钮的约束设置为 0 将使您的按钮保持在中间,并且是解决您的问题的一个干净而好的解决方案。