码迷,mamicode.com
首页 > 其他好文 > 详细

011使用Interface Builder的故事板

时间:2015-06-15 00:08:38      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

效果如下:

技术分享

ViewController.h

1 #import <UIKit/UIKit.h>
2 
3 @interface ViewController : UIViewController
4 @property (strong, nonatomic) IBOutlet UISegmentedControl *colorChoice;
5 @property (strong, nonatomic) IBOutlet UILabel *chosenColor;
6 @property (strong, nonatomic) IBOutlet UIWebView *flowerView;
7 
8 @end

ViewController.m

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 @end
 5 
 6 @implementation ViewController
 7 
 8 - (IBAction)getFlower:(id)sender {
 9     NSString *colorVal;
10     NSInteger colorIndex = self.colorChoice.selectedSegmentIndex;
11     switch (colorIndex) {
12         case 0:
13             colorVal = @"red";
14             break;
15         case 1:
16             colorVal = @"blue";
17             break;
18         case 2:
19             colorVal = @"yellow";
20             break;
21         case 3:
22             colorVal = @"green";
23             break;
24         default:
25             break;
26     }
27     self.chosenColor.text = colorVal;
28     NSString *outputHTML = [[NSString alloc] initWithFormat:@"<body style=‘margin: 0px; padding: 0px‘><img style=‘width:560px, height:420px‘ src=‘http://www.floraphotographs.com/showrandom.php?color=%@‘></body>", colorVal];
29     [self.flowerView loadHTMLString:outputHTML baseURL:nil];
30 }
31 
32 - (void)viewDidLoad {
33     [super viewDidLoad];
34     // Do any additional setup after loading the view, typically from a nib.
35 }
36 
37 - (void)didReceiveMemoryWarning {
38     [super didReceiveMemoryWarning];
39     // Dispose of any resources that can be recreated.
40 }
41 
42 @end

 

011使用Interface Builder的故事板

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4575918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!