how to set (make) a UIButton at bottom of my UITableview?

安稳与你 提交于 2019-12-12 03:19:15

问题


i have two Viewcontroller. one with tableview,check button, add button at bottom . i just adjust my tableview up and kept my add button at bottom. when user press my add button it will take to next viewcontroller ( i did these thing via storyboard )

Needed:

I need my add button should be bottom to above my table view.when user scroll down my table view also it should stick at centre of my tableview.i have tried with creating seperate view ,but no use can't do that.Here this is my viewcontroller.m file:

Thanks in advance !

I used storyboard ,so i did iboutlet and synthesis it,

@interface ViewController ()



@property (strong) NSMutableArray *notes;
@end

@implementation ViewController
@synthesize tableView;
@synthesize addButton;

my 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];
   }

when my add button presses it will move to another viewcontroller:

- (IBAction)addButtonPressed:(id)sender {
    AddNoteViewController *addNoteVC = [AddNoteViewController new];




    // to remove unused warning....
#pragma unused (addNoteVC)

}

Like this i need but in centre ....


回答1:


Since you only want the UIButton to hover over your UITableView the solution should be quite easy.

I just created a UIButton which could the one you using.

in your method where you initialise the UIButton (e.g. 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];

If this shouldn't be your solution feel free to comment this answer!

Edit

To set the width and buttonheight just add the following. Write it above the yourBtn.frame line!

CGFloat buttonwidth = 57.5;
CGFloat buttonheight = 57.5;

Edit 2.0

You need to set the segues identifier first in IB. Check: 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];
}

Cheers




回答2:


I think instead of frame setting in @MasterRazer's answer you should edit or add NSLayoutAttributeCenterX of your UIButton in IB. Setting that constraint of your button to 0 would make your button stays in the middle and be a clean and good solution for your problem.



来源:https://stackoverflow.com/questions/32406586/how-to-set-make-a-uibutton-at-bottom-of-my-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!