{"id":190942,"date":"2023-03-10T20:57:00","date_gmt":"2023-03-10T12:57:00","guid":{"rendered":"https:\/\/www.idc.net\/help\/190942\/"},"modified":"2023-03-10T20:57:00","modified_gmt":"2023-03-10T12:57:00","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9aios%e8%87%aa%e5%8a%a8%e5%b8%83%e5%b1%80","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190942\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1aiOS\u81ea\u52a8\u5e03\u5c40"},"content":{"rendered":"<h2>IOS\u81ea\u52a8\u5e03\u5c40<\/h2>\n<hr>\n<h2>\u7b80\u4ecb<\/h2>\n<p>\u81ea\u52a8\u5e03\u5c40\u5728iOS 6.0\u4e2d\u5f15\u5165\uff0c\u4ec5\u53ef\u4ee5\u652f\u6301IOS6.0 \u53ca \u66f4\u9ad8\u7248\u672c\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u521b\u5efa\u7528\u4e8e\u591a\u4e2a\u79cd\u8bbe\u5907\u7684\u754c\u9762\u3002<\/p>\n<h3>\u5b9e\u4f8b\u6b65\u9aa4<\/h3>\n<p>1.\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 View based application<\/p>\n<p>2.\u4fee\u6539 ViewController.m \u7684\u6587\u4ef6\u5185\u5bb9\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>#import \"ViewController.h\"\n@interface ViewController ()\n@property (nonatomic, strong) UIButton *leftButton;\n@property (nonatomic, strong) UIButton *rightButton;\n@property (nonatomic, strong) UITextField *textfield;\n\n@end\n@implementation ViewController\n\n- (void)viewDidLoad{\n    [super viewDidLoad];\n    UIView *superview = self.view;\n    \/*1. Create leftButton and add to our view*\/\n    self.leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];\n    self.leftButton.translatesAutoresizingMaskIntoConstraints = NO;\n    [self.leftButton setTitle:@\"LeftButton\" forState:UIControlStateNormal];\n    [self.view addSubview:self.leftButton];    \n    \/* 2. Constraint to position LeftButton's X*\/\n    NSLayoutConstraint *leftButtonXConstraint = [NSLayoutConstraint \n    constraintWithItem:self.leftButton attribute:NSLayoutAttributeCenterX \n    relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:\n    NSLayoutAttributeCenterX multiplier:1.0 constant:-60.0f];\n    \/* 3. Constraint to position LeftButton's Y*\/\n    NSLayoutConstraint *leftButtonYConstraint = [NSLayoutConstraint \n    constraintWithItem:self.leftButton attribute:NSLayoutAttributeCenterY \n    relatedBy:NSLayoutRelationEqual toItem:superview attribute:\n    NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f];   \n    \/* 4. Add the constraints to button's superview*\/\n    [superview addConstraints:@[ leftButtonXConstraint,\n    leftButtonYConstraint]];    \n    \/*5. Create rightButton and add to our view*\/\n    self.rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];\n    self.rightButton.translatesAutoresizingMaskIntoConstraints = NO;\n    [self.rightButton setTitle:@\"RightButton\" forState:UIControlStateNormal];\n    [self.view addSubview:self.rightButton];    \n    \/*6. Constraint to position RightButton's X*\/\n    NSLayoutConstraint *rightButtonXConstraint = [NSLayoutConstraint \n    constraintWithItem:self.rightButton attribute:NSLayoutAttributeCenterX \n    relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:\n    NSLayoutAttributeCenterX multiplier:1.0 constant:60.0f];\n    \/*7. Constraint to position RightButton's Y*\/\n    rightButtonXConstraint.priority = UILayoutPriorityDefaultHigh;\n    NSLayoutConstraint *centerYMyConstraint = [NSLayoutConstraint \n    constraintWithItem:self.rightButton attribute:NSLayoutAttributeCenterY \n    relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:\n    NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f];\n    [superview addConstraints:@[centerYMyConstraint,\n    rightButtonXConstraint]];\n   \/\/8. Add Text field\n    self.textfield = [[UITextField alloc]initWithFrame:\n    CGRectMake(0, 100, 100, 30)];\n    self.textfield.borderStyle = UITextBorderStyleRoundedRect;\n    self.textfield.translatesAutoresizingMaskIntoConstraints = NO;\n    [self.view addSubview:self.textfield];\n    \/\/9. Text field Constraints\n    NSLayoutConstraint *textFieldTopConstraint = [NSLayoutConstraint \n    constraintWithItem:self.textfield attribute:NSLayoutAttributeTop \n    relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview \n    attribute:NSLayoutAttributeTop multiplier:1.0 constant:60.0f];\n    NSLayoutConstraint *textFieldBottomConstraint = [NSLayoutConstraint \n    constraintWithItem:self.textfield attribute:NSLayoutAttributeTop \n    relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.rightButton \n    attribute:NSLayoutAttributeTop multiplier:0.8 constant:-60.0f];\n    NSLayoutConstraint *textFieldLeftConstraint = [NSLayoutConstraint \n    constraintWithItem:self.textfield attribute:NSLayoutAttributeLeft \n    relatedBy:NSLayoutRelationEqual toItem:superview attribute:\n    NSLayoutAttributeLeft multiplier:1.0 constant:30.0f];\n    NSLayoutConstraint *textFieldRightConstraint = [NSLayoutConstraint \n    constraintWithItem:self.textfield attribute:NSLayoutAttributeRight \n    relatedBy:NSLayoutRelationEqual toItem:superview attribute:\n    NSLayoutAttributeRight multiplier:1.0 constant:-30.0f];\n    [superview addConstraints:@[textFieldBottomConstraint ,\n    textFieldLeftConstraint, textFieldRightConstraint, \n    textFieldTopConstraint]];   \n}\n- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n}\n@end\n<\/pre>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u5728 iPhone \u6a21\u62df\u5668\u4e0a\u4f1a\u6709\u4e0b\u9762\u7684\u8f93\u51fa\u7ed3\u679c<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211657361183.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u66f4\u6539\u6a21\u62df\u5668\u4e3a\u6a2a\u5411\u7684\u65b9\u5411\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/image\/20171121\/1511254680704169.jpg\" class=\"aligncenter\"><\/p>\n<p>\u6211\u4eec\u5728 iPhone 5 \u6a21\u62df\u5668\u4e0a\u8fd0\u884c\u540c\u4e00\u5e94\u7528\u7a0b\u5e8f\u65f6,\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211658092345.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u66f4\u6539\u6a21\u62df\u5668\u4e3a\u6a2a\u5411\u7684\u65b9\u5411\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b:<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211658478234.jpg\" class=\"aligncenter\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IOS\u81ea\u52a8\u5e03\u5c40 \u7b80\u4ecb \u81ea\u52a8\u5e03\u5c40\u5728iOS 6.0\u4e2d\u5f15\u5165\uff0c\u4ec5\u53ef\u4ee5\u652f\u6301IOS6.0 \u53ca \u66f4\u9ad8\u7248\u672c\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u521b\u5efa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":190943,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190942"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190942\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/190943"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}