【发布时间】:2017-08-03 02:32:10
【问题描述】:
我有未对齐底部中心的按钮?设置为全屏:
使用自动布局设置为底部中心:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *but= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[but addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
int startHeight = 167;
int frameHeight = self.view.frame.size.height - startHeight;
[but setFrame:CGRectMake(0, startHeight, 320, frameHeight)];
[but setTitle:@"Login" forState:UIControlStateNormal];
[but setExclusiveTouch:YES];
[but setImage:[UIImage imageNamed:@"Image"] forState:UIControlStateNormal];
[self.view addSubview:but];
NSDictionary *viewsDict = @{@"but" : but};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-167-[but]-0-|"
options:0 metrics:nil views:viewsDict]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[but]-0-|"
options:0 metrics:nil views:viewsDict]];
}
-(void) buttonClicked:(UIButton*)sender {
NSLog(@"you clicked on button %@", sender.tag);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
【问题讨论】:
标签: ios objective-c iphone ipad autolayout