Position of my UIButton are varying for in all simulator

ⅰ亾dé卋堺 提交于 2019-12-01 21:54:21

问题


I am under one project.In that I created one uibutton at bottom of my viewcontroller using code (Not via storyboard).But when i run my app,my uibutton are placing in differents positions.for example in iphone 5,6 simulator are in some position.In 4s,ipad simulator my uibutton is unvisible.Also i check with my own device(iphone 6) ,in that also my uibutton is not able to see.

Needed

I used below code for creating & placing my button position.but its not fit in one position.

 CGFloat buttonSize = 40;

    UIButton * disButton = [[UIButton alloc] init];
    disButton.backgroundColor = [UIColor redColor];
    UIImage *btnImage = [UIImage imageNamed:@"23"];
    [disButton setImage:btnImage forState:UIControlStateNormal];
    disButton.frame = CGRectMake(150, 523, 40, 40);
    [overlayView addSubview:disButton];
    [disButton addTarget:self action:@selector(dismissPopUpViewController)
        forControlEvents:UIControlEventTouchUpInside];

In my code i use to place position in this line:

disButton.frame = CGRectMake(150, 523, 40, 40);

=> x-position = 150

=> Y-position = 523

Kindly please give some code solution for this problem.


回答1:


As per all comments about your question.You need to set constraint for your UIButon.Use only centre x,centre y because that will helpfull to see your layout in all devices. And there is a already solution for your problem.see these below links for setting auto layout for UIButton

Link 1

Link 2

Link 3

Sure this will help you !



来源:https://stackoverflow.com/questions/32801043/position-of-my-uibutton-are-varying-for-in-all-simulator

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