{"id":561,"date":"2018-02-23T23:40:03","date_gmt":"2018-02-23T15:40:03","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e6%8c%89%e9%92%ae\/"},"modified":"2018-02-23T23:40:03","modified_gmt":"2018-02-23T15:40:03","slug":"ios%e6%8c%89%e9%92%ae","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=561","title":{"rendered":"iOS\u6309\u94ae"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h2>\u6309\u94ae\u4f7f\u7528<\/h2>\n<p>\u6309\u94ae\u7528\u4e8e\u5904\u7406\u7528\u6237\u64cd\u4f5c\u3002\u5b83\u622a\u53d6\u89e6\u6478\u4e8b\u4ef6\uff0c\u5e76\u5c06\u6d88\u606f\u53d1\u9001\u5230\u76ee\u6807\u5bf9\u8c61\u3002<\/p>\n<h2>\u5706\u89d2\u77e9\u5f62\u6309\u94ae<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"button\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/button.jpg\" width=\"246\" height=\"62\"><\/p>\n<h2>\u5728\u00a0xib\u00a0\u4e2d\u7684\u6309\u94ae\u5c5e\u6027<\/h2>\n<p>\u60a8\u53ef\u4ee5\u5728Utility area\uff08\u5b9e\u7528\u533a\u57df\uff0c\u7a97\u53e3\u7684\u53f3\u4fa7\uff09\u7684\u5c5e\u6027\u68c0\u67e5\u5668\u7684\u66f4\u6539 \u00a0xib \u6309\u94ae\u5c5e\u6027\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"buttonAttribute\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/buttonAttribute.jpg\" width=\"183\" height=\"364\" data-pinit=\"registered\"><\/p>\n<p>\u6309\u94ae\u7c7b\u578b<\/p>\n<ul>\n<li>UIButtonTypeCustom<\/li>\n<li>UIButtonTypeRoundedRect<\/li>\n<li>UIButtonTypeDetailDisclosure<\/li>\n<li>UIButtonTypeInfoLight<\/li>\n<li>UIButtonTypeInfoDark<\/li>\n<li>UIButtonTypeContactAdd<\/li>\n<\/ul>\n<p>\u91cd\u8981\u7684\u5c5e\u6027<\/p>\n<ul>\n<li>imageView<\/li>\n<li>titleLabel<\/li>\n<\/ul>\n<p>\u91cd\u8981\u7684\u65b9\u6cd5<\/p>\n<pre>+ (id)buttonWithType:(UIButtonType)buttonType<\/pre>\n<pre>- (UIImage *)backgroundImageForState:(UIControlState)state<\/pre>\n<pre>- (UIImage *)imageForState:(UIControlState)state<\/pre>\n<pre>- (void)setTitle:(NSString *)title forState:(UIControlState)state<\/pre>\n<pre>- (void)addTarget:(id)target action:(SEL)action forControlEvents: (UIControlEvents) controlEvents<\/pre>\n<p>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u65b9\u6cd5\u00a0addDifferentTypesOfButton<\/p>\n<pre>-(void)addDifferentTypesOfButton\n{\n    \/\/ A rounded Rect button created by using class method\n    UIButton *roundRectButton = [UIButton buttonWithType:\n    UIButtonTypeRoundedRect];\n    [roundRectButton setFrame:CGRectMake(60, 50, 200, 40)];\n    \/\/ sets title for the button\n    [roundRectButton setTitle:@\"Rounded Rect Button\" forState:\n    UIControlStateNormal];\n    [self.view addSubview:roundRectButton];\n\n    UIButton *customButton = [UIButton buttonWithType: UIButtonTypeCustom];\n    [customButton setBackgroundColor: [UIColor lightGrayColor]];\n    [customButton setTitleColor:[UIColor blackColor] forState:\n    UIControlStateHighlighted];\n    \/\/sets background image for normal state\u00a0\u00a0\u00a0\u00a0\n    [customButton setBackgroundImage:[UIImage imageNamed:\n    @\"Button_Default.png\"] \n    forState:UIControlStateNormal];\n    \/\/sets background image for highlighted state\n    [customButton setBackgroundImage:[UIImage imageNamed: \n    @\"Button_Highlighted.png\"] \n    forState:UIControlStateHighlighted];\n    [customButton setFrame:CGRectMake(60, 100, 200, 40)];\n    [customButton setTitle:@\"Custom Button\" forState:UIControlStateNormal];\n    [self.view addSubview:customButton];\n\n    UIButton *detailDisclosureButton = [UIButton buttonWithType:\n    UIButtonTypeDetailDisclosure];\n    [detailDisclosureButton setFrame:CGRectMake(60, 150, 200, 40)];\n    [detailDisclosureButton setTitle:@\"Detail disclosure\" forState:\n    UIControlStateNormal];\n    [self.view addSubview:detailDisclosureButton];\n\n    UIButton *contactButton = [UIButton buttonWithType:\n    UIButtonTypeContactAdd];\n    [contactButton setFrame:CGRectMake(60, 200, 200, 40)];\n    [self.view addSubview:contactButton];\n\n    UIButton *infoDarkButton = [UIButton buttonWithType:\n    UIButtonTypeInfoDark];\n    [infoDarkButton setFrame:CGRectMake(60, 250, 200, 40)];\n    [self.view addSubview:infoDarkButton];\n\n    UIButton *infoLightButton = [UIButton buttonWithType:\n    UIButtonTypeInfoLight];\n    [infoLightButton setFrame:CGRectMake(60, 300, 200, 40)];\n    [self.view addSubview:infoLightButton];\n}<\/pre>\n<h2>\u6ce8\u610f\uff1a<\/h2>\n<p>\u6211\u4eec\u5c06\u547d\u540d\u4e3a&#8221;Button_Default.png&#8221;\u548c&#8221;Button_Highlighted.png&#8221;\u7684\u4e2a\u56fe\u50cf\u6dfb\u52a0\u5230\u6211\u4eec\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u56fe\u50cf\u62d6\u5230\u5217\u51fa\u4e86\u6211\u4eec\u7684\u9879\u76ee\u6587\u4ef6\u7684\u5bfc\u822a\u533a\u57df\u6765\u5b8c\u6210\u3002<\/p>\n<p>\u5728\u00a0ViewController.m\u00a0\u4e2d\u66f4\u65b0\u00a0viewDidLoad\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>(void)viewDidLoad\n{\n\u00a0\u00a0\u00a0\u00a0[super viewDidLoad];\n\u00a0\u00a0\u00a0\u00a0\/\/The custom method to create our different types of button is called\n\u00a0\u00a0\u00a0\u00a0[self addDifferentTypesOfButton];\n\u00a0\u00a0\u00a0\u00a0\/\/Do any additional setup after loading the view, typically from a nib\n}<\/pre>\n<h2>\u8f93\u51fa<\/h2>\n<p>\u73b0\u5728\u5f53\u6211\u4eec\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\u6211\u4eec\u5c31\u4f1a\u5f97\u5230\u4e0b\u9762\u7684\u8f93\u51fa\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"buttonOutput\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/buttonOutput.jpg\" width=\"182\" height=\"370\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">\u6309\u94ae\u4f7f\u7528 \u6309\u94ae\u7528\u4e8e\u5904\u7406\u7528\u6237\u64cd\u4f5c\u3002\u5b83\u622a\u53d6\u89e6\u6478\u4e8b\u4ef6\uff0c\u5e76\u5c06\u6d88\u606f\u53d1\u9001\u5230\u76ee\u6807\u5bf9\u8c61\u3002 \u5706\u89d2\u77e9\u5f62\u6309\u94ae \u5728&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=561\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-561","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=561"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/561\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}